LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   PATH in SSH (https://www.linuxquestions.org/questions/linux-general-1/path-in-ssh-4175544835/)

hnasr2001 06-08-2015 03:28 PM

PATH in SSH
 
I am using Centos 6.x

When I ssh to a server and try to use an executable software, I have to use PATH=$PATH/location_of_software/

When I check the usre's PATH, in the .bash_profile file, this line already exist.
How can I permanently set the PATH for SSH user?

joec@home 06-08-2015 03:55 PM

Are you using ssh direct to that user account, or switching user after log in? I'm thinking either you need the "su -" specifically with the "-" switch to force .bash_profile, or there is a typo somewhere in the .bash_profile script.

hnasr2001 06-09-2015 10:26 PM

Replay to joec@home:
I am using ssh direct to the user account.
if switch to su - then everything works.

pan64 06-10-2015 02:18 AM

I think ssh does not use .bash_profile directly (because it is not an interactive shell - see man bash, invocation), so you need explicitly do that:
Code:

ssh user@host 'source ~/.bash_profile; your_app'
- or -
ssh user@host 'bash -l your_app'

(not tested)

joec@home 06-10-2015 01:32 PM

Quote:

Originally Posted by pan64 (Post 5374970)
I think ssh does not use .bash_profile directly (because it is not an interactive shell - see man bash, invocation), so you need explicitly do that:
Code:

ssh user@host 'source ~/.bash_profile; your_app'
- or -
ssh user@host 'bash -l your_app'

(not tested)

.bash_profile should work so long as you are looking at the .bash_profile of the user account your signing into rather than the one you are connecting from.

suicidaleggroll 06-10-2015 01:46 PM

Quote:

Originally Posted by joec@home (Post 5375218)
.bash_profile should work so long as you are looking at the .bash_profile of the user account your signing into rather than the one you are connecting from.

I think pan64 was saying that .bash_profile will only be sourced for an interactive session. If the OP is ssh'ing in and running the command directly, eg:
Code:

$ ssh host command
.bash_profile will not be sourced. However if he connected interactively and THEN ran the command, eg:
Code:

$ ssh host
$ command

it would.


All times are GMT -5. The time now is 07:43 AM.