小编110*_*2ch的帖子

为什么 ssh -t 选项在重定向输出中添加 cr 和 lf

我用 putty 从 windowsbox 连接到 linux box。之后我执行以下操作:

在服务器A上:

serverA: file /etc/motd
/etc/motd: : ASCII English text
Run Code Online (Sandbox Code Playgroud)

在服务器B上:

serverB: ssh -t user@serverA "cat /etc/motd" > /etc/motd.serverA
serverB: file /etc/motd.serverA
/etc/motd.serverA:  ASCII text, with CRLF line terminators
Run Code Online (Sandbox Code Playgroud)

为什么重定向后的输出现在有 CR 和 LF?仅当使用 ssh 的 -t 选项时才会发生这种情况。如果我需要使用 sudo 在 ssh 登录上运行命令,则需要 -t 。例如:

serverB: ssh -t user@serverA "sudo cat /etc/shadow" > /etc/shadow
Run Code Online (Sandbox Code Playgroud)

感谢您的建议

linux ssh io-redirection cat

5
推荐指数
1
解决办法
4840
查看次数

标签 统计

cat ×1

io-redirection ×1

linux ×1

ssh ×1