This project is read-only.

ssh.net $Path not returning everything

Dec 17, 2013 at 12:26 PM
Hi,

in my code, i have this line that passes the command to the unix box
var cmd = ssh.CreateCommand(string.Format("pwd ; echo $PATH"));
what it returned is
/users01/myname
/usr/bin:/usr/sbin:/sbin

but when I type $PATH through Putty, I get a lot more than just "/usr/bin:/usr/sbin:/sbin" is there anything that I'm missing?
Jan 10, 2014 at 3:55 PM
With putty, you have an interactive shell, and many files are sourced (.bash_profile, .bashrc, .profile...).
With a non interactive shell (this is the case with CreateCommand()), a subset or none of those files are sourced, it depends on the registered shell with the user account, and the linux system (archlinux/debian).

What you can do, the most secure/sure way, is to edit your sshd_config file, add "PermitUserEnvironment yes", restart sshd, then create a file ~/.ssh/environment and set the environment variable you want.

If you can't do it, you can still prefix each command :
"pwd; echo $PATH" => "pwd; PATH=$PATH:/something echo $PATH"
Jan 24, 2014 at 11:44 AM
the most secure/sure way, is to edit your sshd_config file, add "PermitUserEnvironment yes", restart sshd, then create a file ~/.ssh/environment and set the environment variable you want.
where can I find the config file?
I would prefer not to do
"pwd; echo $PATH" => "pwd; PATH=$PATH:/something echo $PATH"
as there're lots of env variables.