$ SSH_AUTH_SOCK= rsync x brick:
Enter passphrase for key '/home/alan/.ssh/id_rsa':
[email protected]: Permission denied (publickey).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.3]
rsync 支持带有--rsh
. rsh(例如ssh
)如何能够写入消息,并且不会将它们误解为来自服务器上的 rsync 进程?
答案1
SSH 通过单独的文件描述符提示并读取登录密码;它确保打开当前的 TTY。
大多数程序都会照顾到读来自 TTY 的登录密码,以便他们可以通过暂时禁用 TTY 上的“回显”来阻止显示密码。为了稳健起见,我希望他们确保将提示写入同一个 TTY。
$ SSH_AUTH_SOCK= strace -f rsync x brick:
...
[pid 26255] openat(AT_FDCWD, "/dev/tty", O_RDWR) = 4
[pid 26255] ioctl(4, TCGETS, {B38400 opost isig icanon echo ...}) = 0
[pid 26255] ioctl(4, SNDCTL_TMR_CONTINUE or TCSETSF, {B38400 opost isig icanon -echo ...}) = 0
...
[pid 26255] write(4, "Enter passphrase for key '/home/"..., 51Enter passphrase for key '/home/alan/.ssh/id_rsa': ) = 51
[pid 26255] read(4, "", 1) = 0
[pid 26255] write(4, "\n", 1
) = 1
[pid 26255] ioctl(4, SNDCTL_TMR_CONTINUE or TCSETSF, {B38400 opost isig icanon echo ...}) = 0
...
SSH 将错误消息打印到标准错误(打开文件号 2),而不是 rsync 将用于其协议的标准输出(打开文件号 1)。
[pid 26255] write(2, "[email protected]: "..., [email protected]: Permission denied (publickey).
) = 64
[pid 26255] exit_group(255) = ?