SSH Keypair Setup
When you want to connect to a remote machine, the method is called “Secure Shell”. This creates a connection between the local machine (where your terminal window lives) and the “remote” machine (where the commands you will send actually execute). In order for the local and remote machines to authenticate (trust) each other, we have to create a special password-like files called a keypair. It is called a keypair because there is a public version and a private version. Read more about SSH Keys.
Open a terminal (on your laptop) if not already open. By default, every time you open a terminal it will open in your home directory.
At the command prompt run the following command:
ssh-keygen -t rsa -b 2048
and press enterYou will see this prompt, just press enter
Generating public/private rsa key pair. Enter file in which to save the key (/home/User/.ssh/id_rsa):
You will see this prompt, just press enter
Created directory '/home/User/.ssh'. Enter passphrase (empty for no passphrase):
You will see this prompt, just press enter
Enter same passphrase again:
You will see these messages (your randomart will look different) and your keypair has been created.
Your identification has been saved in /home/User_name/.ssh/id_rsa. Your public key has been saved in /home/User_name/.ssh/id_rsa.pub. The key fingerprint is: SHA256:xPJtMLmJSO73x/NQo3qMpqF6r6St4ONmshS8QZqfmHA User_name@WinDev1802Eval The key's randomart image is: +---[RSA 2048]----+ | | | . . | | . . . * | |+. o . = * | |++E o . S o o | |.=+o . o . | |+oo o o +o | |+= +.o oo.*. | |*+=++ooooo o. | +----[SHA256]-----+
See your key files
Open a terminal if not already open
Change to your .ssh directory
- This is a hidden directory so if you list your files using ls you won’t see it. For seeing all files, use ls -la.
- To change into the .ssh directory type
cd .ssh
Type
pwd
to print your current working directory.Windows users in Powershell will see:
PS C:\\Users\\your_name\.ssh> pwd Path ---- C:\\Users\\your_name\.ssh PS C:\\Users\\your_name\.ssh>
Mac users will see:
pwd /Users/myusername/.ssh
Linux users will see:
$ pwd /home/myusername/.ssh
Next, we need to open the new key file we just made.
Type
ls
to list the files in the directory.- What is displayed may look different. You will not have a config file unless you have already created one.
Type
ls -la
to list all the files in the directory, even the hidden ones.- What is displayed may look different. You will not have a config file unless you have already created one.
Get your public key info
The file id_rsa is your private key and this file will not leave your computer.
The file id_rsa.pub is the public key, whose contents we will upload to cloud services so you authenticate.
The known_hosts is a file that gets generated as you connect to different remote systems.
- This is useful so you know you are connecting to the same server as previous times.
\$ ls -la total 32 drwxr-xr-x 6 your_name staff 192 May 29 20:39 . drwxr-xr-x+ 75 your_name staff 2400 May 30 13:35 .. -rw-r--r-- 1 your_name staff 181 May 29 15:50 config -r-------- 1 your_name staff 3243 May 29 15:50 id_rsa -rw-r--r-- 1 your_name staff 742 May 29 15:50 id_rsa.pub -rw-r--r-- 1 your_name staff 363 May 29 20:42 known_hosts
View the contents of your public_key file by running the command
cat id_rsa.pub
- What is shown is a sample public key, yours will be different
\$ cat id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCnKuIRXwZu0JZH0/Q2XNrYYTaJT7bMtXGhGQaSSOZs6MhQ4SkSbHiygO7RauQf741buLnASzY27GKMMMml6InwfxJWrF60KhNK0r869POQkuZa9v9/cmYcEIzmAJe1xRPABEZ2yfbTG9Wq4sg9cU0mwt1Bx7wiN4QNf0Bak62EC8JWTbcKLduuzO1zabIb5xW9gfR9b4K3HwmqRLl18S8bNsfYQZfvtlwd0mCWQUeuEGbDOgqh//nLIj6DeXdyxbD5xrz79iOAuAK2nXAjNCEtKpxNGQr2Py7aWQjlH+U5laDEHVg4hzmBY7yoZ5eC3Ye45yPqpQA1y8JrbXVhPJRP User\@WinDev1802Eval
Extracting your public key
Open a text editor
(Notepad on Windows or Textpad on Mac, NOT MICROSOFT WORD) and select the output of your terminal with all the text from the ssh-rsa beginning all the way to the end, and paste it in your text editor as-is. We will use this in the next step.- You can also just copy/paste from your terminal screen.
- On a Mac, you can also copy the contents of the id_rsa.pub file using
pbcopy < id_rsa.pub