You are not logged in.

#1 2011-02-06 16:32:28

alexandrebini
Member
Registered: 2011-02-06
Posts: 10

SSH and global $PATH

When I'm logged in my server and type:

$ echo $PATH
I get...
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl

But when I'm NOT logged in and try:

ssh myyser@mysever 'echo $PATH'
i get..
/usr/bin:/bin:/usr/sbin:/sbin

The PATH is correct in my /etc/profile but ssh seems to not load that.

Is there any way to fix it for all users/ssh sessions?

Offline

#2 2011-02-06 18:02:40

Leonid.I
Member
From: Aethyr
Registered: 2009-03-22
Posts: 999

Re: SSH and global $PATH

alexandrebini wrote:

The PATH is correct in my /etc/profile but ssh seems to not load that.

Of course it does not, because ssh's execution shell is a non-login/non-interactive shell.

alexandrebini wrote:

Is there any way to fix it for all users/ssh sessions?

You have to do

ssh user@server 'source /etc/profile; <command>'

EDIT: See also INVOCATION in man bash

Last edited by Leonid.I (2011-02-06 18:05:53)


Arch Linux is more than just GNU/Linux -- it's an adventure
pkill -9 systemd

Offline

#3 2011-02-06 18:27:16

alexandrebini
Member
Registered: 2011-02-06
Posts: 10

Re: SSH and global $PATH

the problem is that i need it to deploy my rails application with capistrano, so i cant edit the ssh command to point the source...

I know i can add the PATH into capistrano config, but i have many apps and would be a problem add in each.

Ubuntu does something different? This doesn't happen there...

Offline

#4 2011-02-06 19:06:56

Leonid.I
Member
From: Aethyr
Registered: 2009-03-22
Posts: 999

Re: SSH and global $PATH

I don't know where ssh takes default PATH (which isn't the same in Ubuntu), but there is nothing different about Ubuntu -- try, for example, executing 'echo $PS1' over ssh.

I see your problem now. Perhaps, you can try tweaking /etc/environment. This file is used by pam_env library, which is called in /etc/pam.d/sshd. See "man pam_env" for more details...

Last edited by Leonid.I (2011-02-06 22:25:48)


Arch Linux is more than just GNU/Linux -- it's an adventure
pkill -9 systemd

Offline

#5 2011-02-06 22:00:10

Damnshock
Member
From: Barcelona
Registered: 2006-09-13
Posts: 414

Re: SSH and global $PATH

The environment is hard coded into sshd ( see "# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin" from the the sshd_config file).

The reason why you get a different path when you login is because the /etc/profile script is executed as well as any executable file (executable by the user you are trying to login) in by the folder /etc/profile.d. [this comes from a function placed in /etc/profile].

You'll face a similar problem if you try to use cron...

Regards


My blog: blog.marcdeop.com
Jabber ID: damnshock@jabber.org

Offline

#6 2011-02-06 22:24:17

Leonid.I
Member
From: Aethyr
Registered: 2009-03-22
Posts: 999

Re: SSH and global $PATH

Damnshock wrote:

The environment is hard coded into sshd ( see "# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin" from the the sshd_config file).

Duh, my sshd_config is 600 root:root yikes

Last edited by Leonid.I (2011-02-06 22:24:37)


Arch Linux is more than just GNU/Linux -- it's an adventure
pkill -9 systemd

Offline

#7 2011-02-06 22:37:12

Damnshock
Member
From: Barcelona
Registered: 2006-09-13
Posts: 414

Re: SSH and global $PATH

Leonid.I wrote:
Damnshock wrote:

The environment is hard coded into sshd ( see "# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin" from the the sshd_config file).

Duh, my sshd_config is 600 root:root yikes

So what? That's just a config file. Besides, it's how it should be! wink


My blog: blog.marcdeop.com
Jabber ID: damnshock@jabber.org

Offline

#8 2011-02-07 11:08:00

alexandrebini
Member
Registered: 2011-02-06
Posts: 10

Re: SSH and global $PATH

Leonid.I wrote:

I don't know where ssh takes default PATH (which isn't the same in Ubuntu), but there is nothing different about Ubuntu -- try, for example, executing 'echo $PS1' over ssh.

I see your problem now. Perhaps, you can try tweaking /etc/environment. This file is used by pam_env library, which is called in /etc/pam.d/sshd. See "man pam_env" for more details...


It's works!

Thank you!

Offline

#9 2011-02-08 13:29:58

Damnshock
Member
From: Barcelona
Registered: 2006-09-13
Posts: 414

Re: SSH and global $PATH

alexandrebini wrote:
Leonid.I wrote:

I don't know where ssh takes default PATH (which isn't the same in Ubuntu), but there is nothing different about Ubuntu -- try, for example, executing 'echo $PS1' over ssh.

I see your problem now. Perhaps, you can try tweaking /etc/environment. This file is used by pam_env library, which is called in /etc/pam.d/sshd. See "man pam_env" for more details...


It's works!

Thank you!

It would help others if you wrote here what you did.

Please add [SOLVED] to the thread title.

Regards


My blog: blog.marcdeop.com
Jabber ID: damnshock@jabber.org

Offline

Board footer

Powered by FluxBB