.bashrc at ssh login [closed]

2019-01-07 01:42发布

When I ssh into my ubuntu-box running Hardy 8.04, the environment variables in my .bashrc are not set.

If I do a source .bashrc, the variables are properly set, and all is well.

How come .bashrc isn't run at login?

标签: ubuntu ssh bash
4条回答
手持菜刀,她持情操
2楼-- · 2019-01-07 02:13

I had similar situation like Hobhouse. I wanted to use command

 ssh myhost.com 'some_command'

and 'some_command' exists in '/var/some_location' so I tried to append '/var/some_location' in PATH environment by editing '$HOME/.bashrc'

but that wasn't working. because default .bashrc(Ubuntu 10.4 LTS) prevent from sourcing by code like below

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

so If you want to change environment for ssh non-login shell. you should add code above that line.

查看更多
Root(大扎)
3楼-- · 2019-01-07 02:16

.bashrc is not sourced when you log in using SSH. You need to source it in your .bash_profile like this:

if [ -f ~/.bashrc ]; then
  . ~/.bashrc
fi
查看更多
该账号已被封号
4楼-- · 2019-01-07 02:26

If ayman's solution doesn't work, try naming your file .profile instead of .bash_profile. That worked for me.

查看更多
叼着烟拽天下
5楼-- · 2019-01-07 02:27

For an excellent resource on how bash invocation works, what dotfiles do what, and how you should use/configure them, read this:

查看更多
登录 后发表回答