SSH key pair authentication is a recommended method of logging into your slot via SSH for added security and convenience in place of our SSH password. You can place the public key on your slot, and then unlock it by connecting to it with a client that has the private key. When the two matches up, the system unlocks without the need for a password.
The major advantage of this is that this authentication method provides greater cryptographic strength than long passwords, rendering it not prone to brute-force attacks. You can increase security even more by protecting your private key with a passphrase.
In this guide, we will be showing you how to generate your own key pair using several tools, how to transfer your public key to your slot and how to login using key pair authentication.
This should work on Linux, macOS and Windows 10 Users. If you haven't set OpenSSH up, you may refer to on how to connect to your slot via SSH for installation and setup of OpenSSH for Windows 10, Linux and MacOS.
ssh-keygen and press ENTER. This should start generating public and private key pairs.
$ ssh-keygen
Generating public/private rsa key pair.
ssh-keygen -b 4096
ssh-keygen -t ed25519
.ssh/ subdirectory in your home directory
C:\\\\Users\\\\username\\\\.ssh/home/username/.ssh$ ssh-keygen -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/your_home/.ssh/id_rsa):
$ ssh-keygen -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/your_home/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
id_rsa.pub) and a private key (id_rsa) stored in your home directory (or on the path you set) that you can use to authenticate when logging into SSH.$ ssh-keygen -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/your_home/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /your_home/.ssh/id_rsa.
Your public key has been saved in /your_home/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:x23Tr+Ee5TlowA+U9HEquagnog3O09EYHQ346WY xan@randomPC
The key's randomart image is:
+---[RSA 4096]----+
|=.=. . o+.. |
|.B o .oo. |
|o.o oo o |
|.+ . oo ... |
| .. . +S+ . |
|. =o== |
|.o. o.=o. |
|o... oE.+o |
| .. .++..o. |
+----[SHA256]-----+
Now, we will import the keys you just generated to your slot. There are several methods for this and is described below.
ssh-copy-id.brew install ssh-copy-idsudo port install openssh +ssh-copy-idcurl -L <https://raw.githubusercontent.com/beautifulcode/ssh-copy-id-for-OSX/master/install.sh> | shssh-copy-id [[email protected]] or ssh-copy-id [email protected]$ ssh-copy-id [email protected]
yes and press ENTER to continue.$ ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/xanban/.ssh/id_rsa.pub"
The authenticity of host 'servername.usbx.me (46.182.109.120)' can't be established.
ECDSA key fingerprint is SHA256:9mQKWg1PVPZtzZ6d5nDjcWUb/Flkuq5VHYRrvwTeRTE.
Are you sure you want to continue connecting (yes/no)?
$ ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/xanban/.ssh/id_rsa.pub"
The authenticity of host 'servername.usbx.me (46.182.109.120)' can't be established.
ECDSA key fingerprint is SHA256:9mQKWg1PVPZtzZ6d5nDjcWUb/Flkuq5VHYRrvwTeRTE.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:
~/.ssh/id_rsa.pub key into a file in your slot's home directory at ~/.ssh called authorized_keys. Then you should see the following output. At this point, your id_rsa.pub key has been uploaded to the slot.$ ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/xanban/.ssh/id_rsa.pub"
The authenticity of host 'servername.usbx.me (46.182.109.120)' can't be established.
ECDSA key fingerprint is SHA256:9mQKWg1PVPZtzZ6d5nDjcWUb/Flkuq5VHYRrvwTeRTE.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '[email protected]'" and check to make sure that only the key(s) you wanted were added.
ssh [email protected] which will go straight to your shell securely. If you set a password for your keys, enter your password.This is another way is to manually copy the contents of your private key file to your slot should ssh-copy-id failed. This method works on Windows, Linux and macOS users.
id_rsa.pub by opening it using your text editor and copy the whole content.ssh with mkdir -p ~/.sshecho public_key_string >> ~/.ssh/authorized_keys replacing public_key_string with the contents of your public key file mkdir -p ~/.ssh
echo ssh-rsa AAAAB3NzaC1ycrandom_characters_here_lol xanban@randomPC >> ~/.ssh/authorized_keys
chmod -R go= ~/.ssh to recursively removes all "group" and "other" permissions for the ~/.ssh/ directory. chmod -R go= ~/.ssh
ssh [[email protected] which will go straight to your slot's shell.
This method works for Windows users only.
![image2019-8-8_19-42-17[1].png](https://prod-files-secure.s3.us-west-2.amazonaws.com/697b3e44-9778-4d03-81bb-de5454d4e844/c92732bb-92c5-4f5d-998d-8de582bd3f8c/image2019-8-8_19-42-171.png)
.ppk formatauthorized_keys file.ssh with mkdir -p ~/.sshecho public_key_string >> ~/.ssh/authorized_keys replacing public_key_string with the generated public key file in PuTTYgen.ultradocs@servername:~$ mkdir -p ~/.ssh
ultradocs@servername:~$ echo ssh-rsa AAAAAAAAlol rsa-key-2012-12-12 >> ~/.ssh/authorized_keys
chmod -R go= ~/.ssh to recursively removes all "group" and "other" permissions for the ~/.ssh/ directory.ultradocs@servername:~$ chmod -R go= ~/.ssh