LLI Wiki — My Digital Knowledge Base

SSH: multiple keys, ProxyJump and failed login troubleshooting

Configure several SSH keys, a ProxyJump bastion, handle legacy ssh-rsa keys and diagnose failed logins.

A collection of practical OpenSSH tips: using several private keys, key-based login setup, converting PuTTY keys, jump hosts, fingerprints, legacy ssh-rsa / ssh-dss issues, and troubleshooting failed logins.

Several private keys with ~/.ssh/config

Use one Host block per remote host, each pointing to its own key:

Host myshortname realname.example.com
    HostName realname.example.com
    IdentityFile ~/.ssh/realname_rsa    # private key for realname
    User remoteusername

Host myother realname2.example.org
    HostName realname2.example.org
    IdentityFile ~/.ssh/realname2_rsa   # different private key for realname2
    User remoteusername

Create the .ssh folder and set the usual permissions:

mkdir -p ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/config
chmod 600 ~/.ssh/config

chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
chmod 600 ~/.ssh/authorized_keys
chmod 644 ~/.ssh/known_hosts

Password-less login with a key pair

Generate a key pair on machine A (user a):

a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.

Create ~/.ssh for user b on machine B (it may already exist), then append the public key to authorized_keys. The password of b is requested each time:

ssh b@B mkdir -p .ssh
cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'

From now on ssh b@B works without a password. On B, restrict the permissions:

chmod 700 .ssh; chmod 640 .ssh/authorized_keys

Use a PuTTY key with OpenSSH

  1. Open PuTTYgen and click Load, then load your private key.
  2. Go to Conversions > Export OpenSSH key and export the private key.
  3. Copy it to ~/.ssh/id_rsa (or id_dsa).
  4. Create the RFC 4716 version of the public key:
ssh-keygen -e -f ~/.ssh/id_dsa > ~/.ssh/id_dsa_com.pub
  1. Convert it to OpenSSH format:
ssh-keygen -i -f ~/.ssh/id_dsa_com.pub > ~/.ssh/id_dsa.pub

Windows Explorer on the WSL .ssh folder showing key files

Key fingerprints

MD5 fingerprint of an RSA key:

ssh-keygen -E md5 -lf ~/.ssh/id_rsa

Standard SHA256 fingerprint:

ssh-keygen -lf ~/.ssh/id_rsa

Jump host (ProxyJump)

Reach a server through a bastion host:

Host bastion01
  HostName bastion01.example.com
  User remoteusername
  IdentityFile ~/.ssh/id_rsa

Host server01
  HostName server01.example.com
  User remoteusername
  ProxyJump bastion01
  IdentityFile ~/.ssh/id_rsa

On the command line: ssh -J user@bastion.example.com user@server.example.com -vvv.

Legacy ssh-rsa / ssh-dss keys refused

Recent OpenSSH versions disable ssh-rsa (and ssh-dss) signatures by default. For an old device or server, re-enable the algorithm. List the supported key types first:

ssh -Q key

In ~/.ssh/config:

Host router
   #HostKeyAlgorithms +ssh-dss
   #PubkeyAcceptedKeyTypes +ssh-dss
   PubkeyAcceptedKeyTypes +ssh-rsa
   HostName 192.0.2.10
   Port 2222
   User remoteusername
   IdentityFile ~/.ssh/router_key

Or on the command line:

ssh -p 2222 -i ~/.ssh/router_key -o PubkeyAcceptedKeyTypes=+ssh-rsa remoteusername@192.0.2.10

Troubleshooting a failed login

Debug from the client

ssh <server> -vvv

A line such as debug3: receive packet: type 51 means the server refused the offered key (SSH_MSG_USERAUTH_FAILURE), so look at the server side.

Look at the server logs

Failed passwords:

grep "Failed password" /var/log/auth.log

If the log file does not exist, check the syslog configuration in /etc/rsyslog.conf. Under journald:

journalctl _SYSTEMD_UNIT=ssh.service | egrep "Failed|Failure"
journalctl _SYSTEMD_UNIT=sshd.service | egrep "Failed|Failure"   # RHEL, CentOS

To get more detail, raise the log level in /etc/ssh/sshd_config:

SyslogFacility AUTH
SyslogFacility AUTHPRIV
LogLevel DEBUG

and make sure /etc/rsyslog.conf routes authentication messages:

authpriv.* /var/log/secure
auth.* /var/log/secure

Then restart both services:

sudo systemctl restart sshd
sudo systemctl restart rsyslog

Read /var/log/secure on CentOS/RHEL, /var/log/auth.log on other distributions.

Typical cause: permissions

sshd silently ignores authorized_keys when the home directory or the .ssh folder is writable by group or others. Fix:

sudo chmod g-w /home/user
sudo chmod 700 /home/user
sudo chmod 700 /home/user/.ssh
sudo chmod 600 /home/user/.ssh/authorized_keys

The same applies to a service account whose home is a custom directory: chmod 700 on the home and .ssh, chmod 600 on authorized_keys.

References

Screenshots

Failed sshd log: bad ownership or modes on the home directory

Mastodon LLIMastodon SocialFosstodon