我想ssh example.com 'ls'按照 ssh 联机帮助页执行类似的操作:
如果指定了命令,它将在远程主机上执行,而不是在登录 shell 上执行。
所以会发生什么是ls显示其输出然后 ssh 退出。
我无法弄清楚如何打开完整的登录外壳,然后在该外壳内运行命令。运行命令后让 shell 保持打开状态。好像我手动完成了以下操作:
localhost$ ssh example.com
example.com$ ls
/folder1
/folder2
example.com$ _
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
小智 48
只需告诉 bash 执行ls,然后在登录 shell 中执行
$ ssh user@host -t 'bash -l -c "ls;bash"'
Run Code Online (Sandbox Code Playgroud)
use*_*686 36
ssh user@host -t 'ls; exec $SHELL -l'
Run Code Online (Sandbox Code Playgroud)
-t强制伪终端分配。这可用于在远程机器上执行任意基于屏幕的程序。略比bash -i.
exec 没有创建新进程。
-l按此顺序查找 ~/.bash_profile、~/.bash_login 和 ~/.profile,并读取和执行来自 ... from ~/.profile 不会在没有-l标志的情况下执行:
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
74305 次 |
| 最近记录: |