LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-08-2015, 03:28 PM   #1
hnasr2001
Member
 
Registered: Nov 2012
Posts: 98

Rep: Reputation: Disabled
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?

Last edited by hnasr2001; 06-08-2015 at 03:32 PM.
 
Old 06-08-2015, 03:55 PM   #2
joec@home
Member
 
Registered: Sep 2009
Location: Galveston Tx
Posts: 291

Rep: Reputation: 70
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.
 
Old 06-09-2015, 10:26 PM   #3
hnasr2001
Member
 
Registered: Nov 2012
Posts: 98

Original Poster
Rep: Reputation: Disabled
Replay to joec@home:
I am using ssh direct to the user account.
if switch to su - then everything works.
 
Old 06-10-2015, 02:18 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
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)
 
Old 06-10-2015, 01:32 PM   #5
joec@home
Member
 
Registered: Sep 2009
Location: Galveston Tx
Posts: 291

Rep: Reputation: 70
Quote:
Originally Posted by pan64 View Post
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.
 
Old 06-10-2015, 01:46 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by joec@home View Post
.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.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Locate second disk path from ssh and copy a folder to it ASTRAPI Linux - Newbie 8 06-10-2010 07:46 AM
What is the effective SSH $PATH when executing a command nlainus Linux - Newbie 7 02-19-2009 05:01 PM
ssh-keygen and path issue pgte3 Other *NIX 2 01-29-2009 07:03 AM
ssh setting a user path ok4life Linux - Server 4 10-26-2006 07:39 PM
Why is $PATH different with SSH than su -? nick99 Red Hat 6 09-09-2004 06:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration