SSH Keys and Passwordless Authentication

SSH Keys and Passwordless Authentication

Ensure that you have the public key in OpenSSH format. To generate a public key in OpenSSH format, you can use the ssh-keygen command with the -y and -f flags, followed by the path to your private key:

ssh-keygen -y -f ~/.ssh/id_rsa > "%HOMEDRIVE%%HOMEPATH%\.ssh\"

Now, copy that public key to your home directory on a remote server:

scp -P 22001 ~/.ssh/

Then log in to the remote server:

ssh -p 22001

# append a key to a authorised_keys file
cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys.backup
cat ~/ >> ~/.ssh/authorized_keys

# add the same public key to the virtual machine
ssh-copy-id -i ~/ root@apach-1

# now I can delete a file
rm -f ~/

Configure client for easier connection:

set F="%HOMEDRIVE%%HOMEPATH%\.ssh\config"
echo. >> %F%
echo Host savioko >> %F%
echo     HostName >> %F%
echo     User upravitelj >> %F%
echo     Port 22001 >> %F%
echo     IdentityFile "~/.ssh/id_rsa" >> %F%
echo     IdentitiesOnly yes >> %F%

This is it. Check that you can log in with keys, and disable password login after that.

ssh savioko

Disable SSH Password Authentication for added security

Edit /etc/ssh/sshd_config and these must be set as follows:

ChallengeResponseAuthentication no
PasswordAuthentication no

And reload SSH server configuration:

service ssh reload

Problem: Public Key File Formats

The two major implementations of OpenSSH and SSH Secure Shell (“SSH2”) use different file formats for SSH-2 protocol keys.

OpenSSH public keys for the SSH-2 protocol begin like this:

ssh-rsa ...

SSH Secure Shell (RFC 4716) public keys for the SSH-2 protocol look like this:


These keys are installed differently too. For OpenSSH, you insert your public keys into the file ~/.ssh/authorized_keys. For SSH Secure Shell, you copy your public key files into the directory ~/.ssh2 and reference them in the file ~/.ssh2/authorization by name:

You can easily convert SSH2 to OpenSSH public key formats, and vice versa. Command line switches are -i or -e. For example, SSH2 to OpenSSH, in Linux:

ssh-keygen -i -f ~/.ssh/ > ~/.ssh/
date 08. Apr 2013 | modified 10. Jun 2024
filename: SSH Public-Key Authentication