linux - SSH remote machine and execute command -
i sshing remote machine , executing command $path on remote machine set $path of user in original machine , not of sshed machine. if ssh remote machine , execute echo $path, set correctly logged in user in new machine
root@host1> ssh admin@remotemachine echo $path this prints path of user, in case root on host1 , not admin on remotemachine
root@host1> ssh admin@remotemachine admin@remotemachine's password: **** echo $path above works fine
basically it's not changing environment new user on remote machine. somehow though logged in remote machine, preserves environment of root host1. if ls -al /, shows directories remote machine, means logged in remote machine
let's use set -x debug run:
$ set -x $ ssh localhost echo $path + ssh localhost echo /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games the line + tells command actually run is:
ssh localhost echo /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games unsurprisingly, value back, regardless of remote path is.
we can single quote command ensure send echo $path instead of echo /usr/local/bin:... server:
$ ssh localhost 'echo $path' + ssh localhost 'echo $path' now set -x shows ssh being run unexpanded command instead of expanded command, , remote path in return.
Comments
Post a Comment