How to set PATH when running a ssh command? The Next CEO of Stack OverflowNone of the dot-files is sourced when running bash via ssh, part IIWrong root shell in /etc/passwdWhen is /etc/bash.bashrc invoked?Can 'ssh <host> <command>' be configured to always load server-side startup files?Bash isn't reading (source) .bashrc in AIXMac terminal cannot not execute .bash_profile~/.bash_profile not executed upon login, but ~/.profile isHow to set environment variables to path so it can be read from GUI and command line from the same program?sudo not executing bashrc as expected
MAZDA 3 2006 (UK) - poor acceleration then takes off at 3250 revs
Any way to transfer all permissions from one role to another?
How to write the block matrix in LaTex?
Rotate a column
How do spells that require an ability check vs. the caster's spell save DC work?
Is it okay to store user locations?
A pseudo-riley?
What size rim is OK?
Removing read access from a file
Text adventure game code
When did Lisp start using symbols for arithmetic?
Visit to the USA with ESTA approved before trip to Iran
Term for the "extreme-extension" version of a straw man fallacy?
How to write papers efficiently when English isn't my first language?
How easy is it to start Magic from scratch?
Why is there a PLL in CPU?
What makes a siege story/plot interesting?
Fastest way to shutdown Ubuntu Mate 18.10
Why didn't Khan get resurrected in the Genesis Explosion?
Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?
Why doesn't a table tennis ball float on the surface? How do we calculate buoyancy here?
When airplanes disconnect from a tanker during air to air refueling, why do they bank so sharply to the right?
Whats the best way to handle refactoring a big file?
Horror movie/show or scene where a horse creature opens its mouth really wide and devours a man in a stables
How to set PATH when running a ssh command?
The Next CEO of Stack OverflowNone of the dot-files is sourced when running bash via ssh, part IIWrong root shell in /etc/passwdWhen is /etc/bash.bashrc invoked?Can 'ssh <host> <command>' be configured to always load server-side startup files?Bash isn't reading (source) .bashrc in AIXMac terminal cannot not execute .bash_profile~/.bash_profile not executed upon login, but ~/.profile isHow to set environment variables to path so it can be read from GUI and command line from the same program?sudo not executing bashrc as expected
Assuming user has /bin/bash as the shell in /etc/passwd. Then ssh user@host command runs the command using Bash. However, that shell is neither login nor interactive, which means neither ~/.bash_profile nor ~/.bashrc is sourced. In that case how to set the PATH environment variable so that executables can be found and executed? Is it recommended to prefix the actual command with source ~/.bashrc?
bash ssh
add a comment |
Assuming user has /bin/bash as the shell in /etc/passwd. Then ssh user@host command runs the command using Bash. However, that shell is neither login nor interactive, which means neither ~/.bash_profile nor ~/.bashrc is sourced. In that case how to set the PATH environment variable so that executables can be found and executed? Is it recommended to prefix the actual command with source ~/.bashrc?
bash ssh
1
.bashrcis sourced, but it probably has a test for interactivity at the top. Things you put before that check should apply, and that's what I do to force PATH when the server doesn't allow user environment or use~/.pam_environment.
– muru
Dec 24 '16 at 12:41
add a comment |
Assuming user has /bin/bash as the shell in /etc/passwd. Then ssh user@host command runs the command using Bash. However, that shell is neither login nor interactive, which means neither ~/.bash_profile nor ~/.bashrc is sourced. In that case how to set the PATH environment variable so that executables can be found and executed? Is it recommended to prefix the actual command with source ~/.bashrc?
bash ssh
Assuming user has /bin/bash as the shell in /etc/passwd. Then ssh user@host command runs the command using Bash. However, that shell is neither login nor interactive, which means neither ~/.bash_profile nor ~/.bashrc is sourced. In that case how to set the PATH environment variable so that executables can be found and executed? Is it recommended to prefix the actual command with source ~/.bashrc?
bash ssh
bash ssh
edited Dec 24 '16 at 11:07
Jakuje
16.5k53256
16.5k53256
asked Dec 24 '16 at 9:20
CykerCyker
1,52021532
1,52021532
1
.bashrcis sourced, but it probably has a test for interactivity at the top. Things you put before that check should apply, and that's what I do to force PATH when the server doesn't allow user environment or use~/.pam_environment.
– muru
Dec 24 '16 at 12:41
add a comment |
1
.bashrcis sourced, but it probably has a test for interactivity at the top. Things you put before that check should apply, and that's what I do to force PATH when the server doesn't allow user environment or use~/.pam_environment.
– muru
Dec 24 '16 at 12:41
1
1
.bashrc is sourced, but it probably has a test for interactivity at the top. Things you put before that check should apply, and that's what I do to force PATH when the server doesn't allow user environment or use ~/.pam_environment.– muru
Dec 24 '16 at 12:41
.bashrc is sourced, but it probably has a test for interactivity at the top. Things you put before that check should apply, and that's what I do to force PATH when the server doesn't allow user environment or use ~/.pam_environment.– muru
Dec 24 '16 at 12:41
add a comment |
2 Answers
2
active
oldest
votes
You have got few possibilities:
- Set the
PATHin the server~/.ssh/environment(needs to be enabled byPermitUserEnvironment yesinsshd_config). - Use full path to the binary
- As you mentioned, manually source
.bashrc: prefix the command with. ~/.bashrc(orsource)
It pretty much depends on the use case, which way you will go.
1
Manually sourcing~/.bashrcis not necesary, it happens by default. It fact, it seems to me like a bad idea.
– sorontar
Dec 25 '16 at 3:53
add a comment |
You are equating local settings to remote settings.
Locally, a bash instance, the present running shell in which you write:
ssh user@host command
Will execute the command ssh (nothing more) as a client ssh.
To do so the local shell needs not to start a sub-shell or a new shell or login.
The command is executed as a ls command is: locally.
It is the client ssh command that opens a network connection to a remote system, where, if correctly authenticated, a new shell will be started to execute the command written as an argument to ssh, or, if no argument is given, expect further commands on that connection.
That new Remote shell necessarily will be a login shell as the remote user (to that system) needs to be authenticated to login. Or, if some specific command is given, just run such command with the authenticated user privileges.
You could see which files are sourced by adding a $file sourced to the start of each file (in the remote system)(root is needed to change /etc/ files):
$ a=(~/.bashrc ~/.profile /etc/bash.bashrc /etc/profile)
$ for f in "$a[@]"; do sed -i '1 iecho "'"$f"' was read"n' "$f"; done
And then just start a ssh console:
$ ssh sorontar@localhost
/etc/profile was read
/etc/bash.bashrc was read
/home/sorontar/.profile was read
/home/sorontar/.bashrc was read
In this case, both bashrc files were read because each profile file had commands to include them, not because the login shell directly sourced them.
$ ssh sorontar@localhost :
/etc/bash.bashrc was read
/home/sorontar/.bashrc was read
In this system, where bashrc is read in both cases.
No need to add a source ~/.bashrc to the command to execute.
Change PATH
All you need to do is include the correct settings to change the "$PATH", either in /etc/bash.bashrc for all users that start a shell in this system. Or in ~/.bashrc for each user that needs it. You could add (or edit) an skeleton of an user .bashrc to /etc/skel/ to have any new user created have the correct file available.
The above is valid only for bash. If you need the setting to work for all shells, probably setting the environment variable PATH using the ssh file ~/.ssh/environment for each user that need it. Or use /etc/ssh/sshrc for a global setting in the system where the ssh server is running (please read the Files section in man sshd for some additional detail).
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f332532%2fhow-to-set-path-when-running-a-ssh-command%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have got few possibilities:
- Set the
PATHin the server~/.ssh/environment(needs to be enabled byPermitUserEnvironment yesinsshd_config). - Use full path to the binary
- As you mentioned, manually source
.bashrc: prefix the command with. ~/.bashrc(orsource)
It pretty much depends on the use case, which way you will go.
1
Manually sourcing~/.bashrcis not necesary, it happens by default. It fact, it seems to me like a bad idea.
– sorontar
Dec 25 '16 at 3:53
add a comment |
You have got few possibilities:
- Set the
PATHin the server~/.ssh/environment(needs to be enabled byPermitUserEnvironment yesinsshd_config). - Use full path to the binary
- As you mentioned, manually source
.bashrc: prefix the command with. ~/.bashrc(orsource)
It pretty much depends on the use case, which way you will go.
1
Manually sourcing~/.bashrcis not necesary, it happens by default. It fact, it seems to me like a bad idea.
– sorontar
Dec 25 '16 at 3:53
add a comment |
You have got few possibilities:
- Set the
PATHin the server~/.ssh/environment(needs to be enabled byPermitUserEnvironment yesinsshd_config). - Use full path to the binary
- As you mentioned, manually source
.bashrc: prefix the command with. ~/.bashrc(orsource)
It pretty much depends on the use case, which way you will go.
You have got few possibilities:
- Set the
PATHin the server~/.ssh/environment(needs to be enabled byPermitUserEnvironment yesinsshd_config). - Use full path to the binary
- As you mentioned, manually source
.bashrc: prefix the command with. ~/.bashrc(orsource)
It pretty much depends on the use case, which way you will go.
answered Dec 24 '16 at 9:29
JakujeJakuje
16.5k53256
16.5k53256
1
Manually sourcing~/.bashrcis not necesary, it happens by default. It fact, it seems to me like a bad idea.
– sorontar
Dec 25 '16 at 3:53
add a comment |
1
Manually sourcing~/.bashrcis not necesary, it happens by default. It fact, it seems to me like a bad idea.
– sorontar
Dec 25 '16 at 3:53
1
1
Manually sourcing
~/.bashrc is not necesary, it happens by default. It fact, it seems to me like a bad idea.– sorontar
Dec 25 '16 at 3:53
Manually sourcing
~/.bashrc is not necesary, it happens by default. It fact, it seems to me like a bad idea.– sorontar
Dec 25 '16 at 3:53
add a comment |
You are equating local settings to remote settings.
Locally, a bash instance, the present running shell in which you write:
ssh user@host command
Will execute the command ssh (nothing more) as a client ssh.
To do so the local shell needs not to start a sub-shell or a new shell or login.
The command is executed as a ls command is: locally.
It is the client ssh command that opens a network connection to a remote system, where, if correctly authenticated, a new shell will be started to execute the command written as an argument to ssh, or, if no argument is given, expect further commands on that connection.
That new Remote shell necessarily will be a login shell as the remote user (to that system) needs to be authenticated to login. Or, if some specific command is given, just run such command with the authenticated user privileges.
You could see which files are sourced by adding a $file sourced to the start of each file (in the remote system)(root is needed to change /etc/ files):
$ a=(~/.bashrc ~/.profile /etc/bash.bashrc /etc/profile)
$ for f in "$a[@]"; do sed -i '1 iecho "'"$f"' was read"n' "$f"; done
And then just start a ssh console:
$ ssh sorontar@localhost
/etc/profile was read
/etc/bash.bashrc was read
/home/sorontar/.profile was read
/home/sorontar/.bashrc was read
In this case, both bashrc files were read because each profile file had commands to include them, not because the login shell directly sourced them.
$ ssh sorontar@localhost :
/etc/bash.bashrc was read
/home/sorontar/.bashrc was read
In this system, where bashrc is read in both cases.
No need to add a source ~/.bashrc to the command to execute.
Change PATH
All you need to do is include the correct settings to change the "$PATH", either in /etc/bash.bashrc for all users that start a shell in this system. Or in ~/.bashrc for each user that needs it. You could add (or edit) an skeleton of an user .bashrc to /etc/skel/ to have any new user created have the correct file available.
The above is valid only for bash. If you need the setting to work for all shells, probably setting the environment variable PATH using the ssh file ~/.ssh/environment for each user that need it. Or use /etc/ssh/sshrc for a global setting in the system where the ssh server is running (please read the Files section in man sshd for some additional detail).
add a comment |
You are equating local settings to remote settings.
Locally, a bash instance, the present running shell in which you write:
ssh user@host command
Will execute the command ssh (nothing more) as a client ssh.
To do so the local shell needs not to start a sub-shell or a new shell or login.
The command is executed as a ls command is: locally.
It is the client ssh command that opens a network connection to a remote system, where, if correctly authenticated, a new shell will be started to execute the command written as an argument to ssh, or, if no argument is given, expect further commands on that connection.
That new Remote shell necessarily will be a login shell as the remote user (to that system) needs to be authenticated to login. Or, if some specific command is given, just run such command with the authenticated user privileges.
You could see which files are sourced by adding a $file sourced to the start of each file (in the remote system)(root is needed to change /etc/ files):
$ a=(~/.bashrc ~/.profile /etc/bash.bashrc /etc/profile)
$ for f in "$a[@]"; do sed -i '1 iecho "'"$f"' was read"n' "$f"; done
And then just start a ssh console:
$ ssh sorontar@localhost
/etc/profile was read
/etc/bash.bashrc was read
/home/sorontar/.profile was read
/home/sorontar/.bashrc was read
In this case, both bashrc files were read because each profile file had commands to include them, not because the login shell directly sourced them.
$ ssh sorontar@localhost :
/etc/bash.bashrc was read
/home/sorontar/.bashrc was read
In this system, where bashrc is read in both cases.
No need to add a source ~/.bashrc to the command to execute.
Change PATH
All you need to do is include the correct settings to change the "$PATH", either in /etc/bash.bashrc for all users that start a shell in this system. Or in ~/.bashrc for each user that needs it. You could add (or edit) an skeleton of an user .bashrc to /etc/skel/ to have any new user created have the correct file available.
The above is valid only for bash. If you need the setting to work for all shells, probably setting the environment variable PATH using the ssh file ~/.ssh/environment for each user that need it. Or use /etc/ssh/sshrc for a global setting in the system where the ssh server is running (please read the Files section in man sshd for some additional detail).
add a comment |
You are equating local settings to remote settings.
Locally, a bash instance, the present running shell in which you write:
ssh user@host command
Will execute the command ssh (nothing more) as a client ssh.
To do so the local shell needs not to start a sub-shell or a new shell or login.
The command is executed as a ls command is: locally.
It is the client ssh command that opens a network connection to a remote system, where, if correctly authenticated, a new shell will be started to execute the command written as an argument to ssh, or, if no argument is given, expect further commands on that connection.
That new Remote shell necessarily will be a login shell as the remote user (to that system) needs to be authenticated to login. Or, if some specific command is given, just run such command with the authenticated user privileges.
You could see which files are sourced by adding a $file sourced to the start of each file (in the remote system)(root is needed to change /etc/ files):
$ a=(~/.bashrc ~/.profile /etc/bash.bashrc /etc/profile)
$ for f in "$a[@]"; do sed -i '1 iecho "'"$f"' was read"n' "$f"; done
And then just start a ssh console:
$ ssh sorontar@localhost
/etc/profile was read
/etc/bash.bashrc was read
/home/sorontar/.profile was read
/home/sorontar/.bashrc was read
In this case, both bashrc files were read because each profile file had commands to include them, not because the login shell directly sourced them.
$ ssh sorontar@localhost :
/etc/bash.bashrc was read
/home/sorontar/.bashrc was read
In this system, where bashrc is read in both cases.
No need to add a source ~/.bashrc to the command to execute.
Change PATH
All you need to do is include the correct settings to change the "$PATH", either in /etc/bash.bashrc for all users that start a shell in this system. Or in ~/.bashrc for each user that needs it. You could add (or edit) an skeleton of an user .bashrc to /etc/skel/ to have any new user created have the correct file available.
The above is valid only for bash. If you need the setting to work for all shells, probably setting the environment variable PATH using the ssh file ~/.ssh/environment for each user that need it. Or use /etc/ssh/sshrc for a global setting in the system where the ssh server is running (please read the Files section in man sshd for some additional detail).
You are equating local settings to remote settings.
Locally, a bash instance, the present running shell in which you write:
ssh user@host command
Will execute the command ssh (nothing more) as a client ssh.
To do so the local shell needs not to start a sub-shell or a new shell or login.
The command is executed as a ls command is: locally.
It is the client ssh command that opens a network connection to a remote system, where, if correctly authenticated, a new shell will be started to execute the command written as an argument to ssh, or, if no argument is given, expect further commands on that connection.
That new Remote shell necessarily will be a login shell as the remote user (to that system) needs to be authenticated to login. Or, if some specific command is given, just run such command with the authenticated user privileges.
You could see which files are sourced by adding a $file sourced to the start of each file (in the remote system)(root is needed to change /etc/ files):
$ a=(~/.bashrc ~/.profile /etc/bash.bashrc /etc/profile)
$ for f in "$a[@]"; do sed -i '1 iecho "'"$f"' was read"n' "$f"; done
And then just start a ssh console:
$ ssh sorontar@localhost
/etc/profile was read
/etc/bash.bashrc was read
/home/sorontar/.profile was read
/home/sorontar/.bashrc was read
In this case, both bashrc files were read because each profile file had commands to include them, not because the login shell directly sourced them.
$ ssh sorontar@localhost :
/etc/bash.bashrc was read
/home/sorontar/.bashrc was read
In this system, where bashrc is read in both cases.
No need to add a source ~/.bashrc to the command to execute.
Change PATH
All you need to do is include the correct settings to change the "$PATH", either in /etc/bash.bashrc for all users that start a shell in this system. Or in ~/.bashrc for each user that needs it. You could add (or edit) an skeleton of an user .bashrc to /etc/skel/ to have any new user created have the correct file available.
The above is valid only for bash. If you need the setting to work for all shells, probably setting the environment variable PATH using the ssh file ~/.ssh/environment for each user that need it. Or use /etc/ssh/sshrc for a global setting in the system where the ssh server is running (please read the Files section in man sshd for some additional detail).
edited Mar 10 '17 at 15:15
Community♦
1
1
answered Dec 25 '16 at 3:51
sorontarsorontar
4,548929
4,548929
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f332532%2fhow-to-set-path-when-running-a-ssh-command%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
.bashrcis sourced, but it probably has a test for interactivity at the top. Things you put before that check should apply, and that's what I do to force PATH when the server doesn't allow user environment or use~/.pam_environment.– muru
Dec 24 '16 at 12:41