Bash
Cygwin中使用sshpass,ssh仍然提示輸入密碼
根據此RedHat SSH 密碼自動化指南,我將遵循範例 4:GPG一,並按照該指南中的步驟
pass_file
使用自己的密碼創建我的密碼。然後,我得到了這個:gpg -d -q myappserver23.sshpasswd.gpg > pass_file && sshpass -fpass_file ssh myuser@xxx.xxx.xxx.xxx
注意
-f
選項之間沒有空格,pass_file
根據sshpass 手冊頁 當我執行上面的命令時,我被要求輸入密碼,我輸入正確,然後我被要求輸入伺服器的密碼,就好像sshpass
沒有用過的。簡而言之,這可行,但我仍然收到密碼提示…我
-q
當然知道這些選項,並且我還添加-vvv
了sshpass和ssh,我相信這似乎與shh而不是sshpass有關。我將在這里分享我在 ssh 橫幅消息之後收到的調試消息(...) debug3: input_userauth_banner ---------------------------------------------------------------------------------------- Here goes ssh banner message ---------------------------------------------------------------------------------------- debug3: receive packet: type 51 debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password debug3: preferred publickey,keyboard-interactive,password debug3: authmethod_lookup publickey debug3: remaining preferred: keyboard-interactive,password debug3: authmethod_is_enabled publickey debug1: Next authentication method: publickey debug1: Offering public key: C:\\Users\\myuser/.ssh/id_rsa RSA SHA256:7PAz6lsENYkfYGwFZWNf0OJ88Z9mFDMSBc+P9t+4H1k debug3: send packet: type 50 debug2: we sent a publickey packet, wait for reply debug3: receive packet: type 51 debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password debug1: Trying private key: C:\\Users\\myuser/.ssh/id_dsa debug3: no such identity: C:\\Users\\myuser/.ssh/id_dsa: No such file or directory debug1: Trying private key: C:\\Users\\myuser/.ssh/id_ecdsa debug3: no such identity: C:\\Users\\myuser/.ssh/id_ecdsa: No such file or directory debug1: Trying private key: C:\\Users\\myuser/.ssh/id_ed25519 debug3: no such identity: C:\\Users\\myuser/.ssh/id_ed25519: No such file or directory debug1: Trying private key: C:\\Users\\myuser/.ssh/id_xmss debug3: no such identity: C:\\Users\\myuser/.ssh/id_xmss: No such file or directory debug2: we did not send a packet, disable method debug3: authmethod_lookup password debug3: remaining preferred: ,password debug3: authmethod_is_enabled password debug1: Next authentication method: password debug3: failed to open file:C:/dev/tty error:3 debug1: read_passphrase: can't open /dev/tty: No such file or directory myuser@xxx.xxx.xxx.xxx's password:
此輸出的最後一行是密碼提示。顯然,如果我在這裡輸入我的密碼,我將能夠登錄到遠端伺服器,但是,使用有什麼意義
sshpass
呢?我希望能夠無需輸入任何密碼即可登錄。請不要建議使用私鑰,我知道這個主題,但它不適用於我的現實世界場景。任何幫助將不勝感激。
@KamilMaciorowski 評論讓我朝著正確的方向前進。根據 ServerFault 這個有用的答案,Windows正在採用自己的OpenSSH實現。為了解決這個問題,
openssh
必須在Cygwin中安裝才能使用這個。這解決了錯誤,現在我可以這樣做:
$ gpg -d -q myappserver23.sshpasswd.gpg > pass_file && sshpass -fpass_file ssh myuser@xxx.xxx.xxx.xxx > test.txt $ cat test.txt /home/myuser uid=1001(myuser) gid=1001(mygroup) groups=1001(mygroup)
PD。這不是不安全的,因為我們在
gpg
這裡使用。但如果有疑問,試試這個。