在 ssh 会话中启用 tty [英] enabling tty in a ssh session

查看:249
本文介绍了在 ssh 会话中启用 tty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为编写的脚本获取一些登录信息,供许多用户使用.在 python 中,我将 input_raw 设置为从 dev/tty 读取,但是当我通过 ssh 连接到在服务器上运行的脚本时,它失败了.

想法?解决方法?

我宁愿避免将用户名硬编码到脚本中.

请和谢谢.

解决方案

尝试使用 -t 选项进行 ssh:

<预>-t 强制伪 tty 分配.这可用于执行任意远程机器上的基于屏幕的程序,可以是非常有用,例如在实现菜单服务时.多个 -t选项强制 tty 分配,即使 ssh 没有本地 tty.

~/.ssh/config 中似乎没有等效选项,因此您需要创建一个 shell 脚本.一个简单的就是:

#!/bin/shssh -t "$*"

将其另存为 ssh-t 或其他内容,chmod +x ssh-t,并将其放在您的 PATH 中的某个位置.然后设置 GIT_SSH=ssh-t 告诉 Git 使用这个脚本.

I would to take in some login information for a script have written in to be used by many users. In python I set the input_raw to read from dev/tty but it fails horribly when i am connecting to the script being run on a server through ssh.

Thoughts? Workarounds?

I would prefer to avoid hard coding usernames into the script.

Please and thank you.

解决方案

Try using the -t option to ssh:

     -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.

There doesn't seem to be an equivalent option in ~/.ssh/config, so you will need to create a shell script. A simple one is:

#!/bin/sh

ssh -t "$*"

Save this as ssh-t or something, chmod +x ssh-t, and put it somewhere in your PATH. Then set GIT_SSH=ssh-t to tell Git to use this script.

这篇关于在 ssh 会话中启用 tty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆