【问题标题】:Script called from ~/.ssh/config loses TTY从 ~/.ssh/config 调用的脚本丢失 TTY
【发布时间】:2021-12-30 08:03:40
【问题描述】:

我正在使用一个特定于站点的身份验证脚本,该脚本为无密码登录颁发 24 小时证书。我要做的是装配我的~/.ssh/config,所以ssh 在证书过期时触发脚本:

Match originalhost remotehost.site exec "test $(file.age ~/.ssh/certificate) -ge 86400" exec ~/bin/authentication_script

几乎有效——它可以测试最新证书文件的年龄,如果它已过期,则调用authentication_script。问题是该脚本使用 TTY read 操作来获取密码输入,并给出以下错误:

stty: 'standard input': Inappropriate ioctl for device
stty: 'standard input': Inappropriate ioctl for device
authentication_script: The sshproxy server said: Authentication failed. Failed login: myname: 
authentication_script: This usually means you did not enter the correct password or OTP: 
stty: 'standard input': Inappropriate ioctl for device
stty: 'standard input': Inappropriate ioctl for device
stty: 'standard input': Inappropriate ioctl for device
authentication_script: The sshproxy server said: Authentication failed. Failed login: myname: 
authentication_script: This usually means you did not enter the correct password or OTP: 
stty: 'standard input': Inappropriate ioctl for device

当我从常规登录会话在命令行上运行脚本时,不会发生这种情况。 有什么模式可以翻转来让它工作吗?

【问题讨论】:

  • 使用ssh -t remotehost.site 也不起作用。当 I/O 操作通过 ssh-connection 发生时,它可能会解决问题;不过,这里发生的事情是 ssh 在我的笔记本电脑上本地调用脚本,并且似乎遵循一组不同的重定向规则。
  • 脚本使用read -r -p "Enter the password for ${user}: " -s pw 的形式我希望我能以某种方式添加-u fd Read input from file descriptor fd,以将输入重新连接到我的键盘。

标签: stty password-less ssh-config


【解决方案1】:

有人告诉我exec 禁用了stdin/stdout,并在此处提及:

https://unix.stackexchange.com/questions/674759/how-to-make-ssh-config-match-host-exec-inherit-current-shells-tty-name

但出于我的目的,我可以使用 PTY 操作来控制 I/O:

 PTY=$(ps --no-headers $$ | xargs index 2)
 printf "Enter the password}: " > /dev/$PTY
 read -r -s pw < /dev/$PTY

index 操作只是我从列表中返回第 n 项的脚本)

【讨论】:

    猜你喜欢
    • 2014-12-29
    • 1970-01-01
    • 2017-08-15
    • 2013-05-10
    • 1970-01-01
    • 2019-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多