关于 ssh 命令下 t 参数

2022-05-01 11:00:23 +08:00
 alanhe421

举例有如下命令


ssh -p 22  -t root@111.132.132.65 "tmux -CC attach || tmux -CC"

这个 t 参数是什么含义,远程登录后执行的命令内容?试了下如果不写还不行,--help 查看命令手册,没看到有 t 这个参数

1905 次点击
所在节点    SSH
5 条回复
ynyounuo
2022-05-01 11:02:48 +08:00
man
ericls
2022-05-01 11:03:10 +08:00
man ssh 里面有说明
Xusually
2022-05-01 11:05:29 +08:00
man ssh

-T Disable pseudo-terminal allocation.

-t Force pseudo-terminal allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty alloca-tion, even if ssh has no local tty.

另外,你仔细看看你发的图 Tt 不是都在?
alanhe421
2022-05-01 15:11:35 +08:00
@Xusually 你是说 这里这个吧[-46AaCfGgKkMNnqsTtVvXxYy]
我意思下面的参数带详细描述的没有
wgq2633
2022-05-03 09:39:08 +08:00
lz 的疑点是不是主要在分配或者不分配伪终端的区别,什么是伪终端上面?
这几个命令可以看到区别:

a1. `ssh -t $host 'ls -l /proc/self/fd/'`
lrwx------ 1 xxx xxx 64 May 3 09:30 0 -> /dev/pts/6
lrwx------ 1 xxx xxx 64 May 3 09:30 1 -> /dev/pts/6
lrwx------ 1 xxx xxx 64 May 3 09:30 2 -> /dev/pts/6
a2. `ssh $host 'ls -l /proc/self/fd/'`
lr-x------ 1 xxx xxx 64 May 3 09:31 0 -> pipe:[17376416]
l-wx------ 1 xxx xxx 64 May 3 09:31 1 -> pipe:[17376417]
l-wx------ 1 xxx xxx 64 May 3 09:31 2 -> pipe:[17376418]
分配伪终端的时候,标入 /标出是 pts 伪终端设备; 不分配的时候,就是个管道

b1. `ssh -t $host 'python -c "import os; print(os.get_terminal_size())"'`
os.terminal_size(columns=197, lines=49)
Connection to lo closed.
b2. `ssh $host 'python -c "import os; print(os.get_terminal_size())"' `
Traceback (most recent call last):
File "<string>", line 1, in <module>
OSError: [Errno 25] Inappropriate ioctl for device
使用 python 的 `os.get_terminal_size` 函数获取终端尺寸
分配终端的时候,标准输入 /输出的终端,有物理尺寸(上面例子是 49 行,197 列)也就是跟客户端的这个模拟终端的串口尺寸是物理相关的;
不分配终端的话,标入 /标出就是一个普通的流数据,可以入 /可以出,但是 **没有尺寸**

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/850320

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX