在SSH会话中启用TTY
我想让一个我写的脚本能够接收一些登录信息,以便多个用户使用。在Python中,我把输入设置为从dev/tty读取,但当我通过SSH连接到在服务器上运行的脚本时,这个方法完全失败了。
有什么想法吗?有没有解决办法?
我希望能避免把用户名写死在脚本里。
谢谢!
1 个回答
6
试试在使用ssh时加上 -t
这个选项:
-t Force pseudo-tty allocation. This can be used to execute arbi- trary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.
在 ~/.ssh/config
里似乎没有类似的选项,所以你需要创建一个脚本。一个简单的脚本可以是:
#!/bin/sh
ssh -t "$*"
把这个脚本保存为 ssh-t
或其他名字,然后运行 chmod +x ssh-t
来给它执行权限,最后把它放在你的 PATH
里。接着设置 GIT_SSH=ssh-t
,这样Git就会使用这个脚本了。