我用 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)
感谢您的建议