2

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

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

几乎可以工作 - 它测试最新证书文件的年龄,并调用authentication_script它是否已过期。问题是该脚本使用 TTYread操作来获取密码输入,并给出以下错误:

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

当我从常规登录会话在命令行上运行脚本时,不会发生这种情况。是否有某种模式可以翻转以使其正常工作?

4

1 回答 1

0

我被告知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 项的脚本)

于 2021-11-26T11:41:10.537 回答