通过 ssh 登录,更改远程 PS1 并且不要退出远程 ssh shell

通过 ssh 登录,更改远程 PS1 并且不要退出远程 ssh shell

当我 ssh 另一个 centos 时我想更改 PS1

    strshell = 'PS1="remote!"'
    os.system("ssh -i %s -l%s -p%s %s %s"%(SSH_KEY,SSH_USER,SSH_PORT,des,strshell))  

ssh 自动退出,我想留在这个shell里,如何实现?

我只是换一种方法来做这件事

 tin = ' sudo -i ; export PS1="Remote! \W :"; exec /bin/bash -i'
 os.system("ssh  -i%s -l%s -p%s %s -t%s" % (SSH_KEY, SSH_USER, SSH_PORT, des, tin))  

但是我更改了本地机器提示符而不是远程机器提示符。为什么?
os.system 是一个 python 函数

答案1

也许您需要将其添加到.profile所有主机上的文件中。

if [ -n "$SSH_CLIENT" ]; then
   PS1="Remote! \W : "
else
   PS1="Local: "
fi

相关内容