Issue
I'm setting up my virtual machine in CI such that I can tests a script that uses ssh.
I'm setting up my virtual machine running Ubuntu 20.04.2 LTS as follows:
sudo apt-get install openssh-server
ssh-keygen -t rsa -q -f "$HOME/.ssh/id_rsa" -N ""
cat "$HOME/.ssh/id_rsa.pub" >> "$HOME/.ssh/authorized_keys"
(According to the docs the ssh-server is automatically started, and I verified that this is indeed the case using sudo systemctl status ssh
)
To debug I ran
ssh -v localhost "uname -r"
giving:
OpenSSH_8.2p1 Ubuntu-4ubuntu0.1, OpenSSL 1.1.1f 31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: identity file /home/runner/.ssh/id_rsa type 0
debug1: identity file /home/runner/.ssh/id_rsa-cert type -1
debug1: identity file /home/runner/.ssh/id_dsa type -1
debug1: identity file /home/runner/.ssh/id_dsa-cert type -1
debug1: identity file /home/runner/.ssh/id_ecdsa type -1
debug1: identity file /home/runner/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/runner/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/runner/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/runner/.ssh/id_ed25519 type -1
debug1: identity file /home/runner/.ssh/id_ed25519-cert type -1
debug1: identity file /home/runner/.ssh/id_ed25519_sk type -1
debug1: identity file /home/runner/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/runner/.ssh/id_xmss type -1
debug1: identity file /home/runner/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.1
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to localhost:22 as 'runner'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:NFnWPH2boToKCX0yq1K33LY0K3EwK810f599LpwoXJI
debug1: read_passphrase: can't open /dev/tty: No such device or address
Host key verification failed.
For completeness
cat /var/log/auth.log
gives:
Mar 10 06:13:08 fv-az189-848 php8.0: DIGEST-MD5 common mech free
Mar 10 06:13:09 fv-az189-848 php8.0: DIGEST-MD5 common mech free
Mar 10 06:13:09 fv-az189-848 php8.0: DIGEST-MD5 common mech free
Mar 10 06:13:52 fv-az189-848 sudo: runner : TTY=unknown ; *** ; USER=root ; COMMAND=/usr/bin/apt-get install openssh-server
Mar 10 06:13:52 fv-az189-848 sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
Mar 10 06:13:55 fv-az189-848 sudo: pam_unix(sudo:session): session closed for user root
Mar 10 06:13:55 fv-az189-848 sudo: runner : TTY=unknown ; *** ; USER=root ; COMMAND=/usr/bin/systemctl status ssh
Mar 10 06:13:55 fv-az189-848 sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
Mar 10 06:13:55 fv-az189-848 sudo: pam_unix(sudo:session): session closed for user root
Mar 10 06:13:55 fv-az189-848 sshd[1847]: Connection closed by ::1 port 54242 [preauth]
It seems to me that ssh is finding the key alright, but is trying to read a passphrase that I set to be empty using the -N ""
option here:
ssh-keygen -t rsa -q -f "$HOME/.ssh/id_rsa" -N ""
Therefore, I don't know how to resolve this issue. I could create /dev/tty
but it seems to me that ssh should not even look for it.
Solution
I checked your setting and it works for me.
But my debug output looks different after the Server host key
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:NFnWPH2boToKCX0yq1K33LY0K3EwK810f599LpwoXJI
debug1: Host 'localhost' is known and matches the ECDSA host key.
debug1: Found key in /home/pi/.ssh/known_hosts:15
I assume, that localhost
isn't present in your .ssh/known_host
file, therefore ssh
wants to ask you for your confirmation.
You could try to start without checking
ssh -v localhost "uname -r" -o StrictHostKeyChecking=no
But the underlying problem is your missing /dev/tty
, your current tty seems to be wrong configured in some way
Answered By - jeb