There are several methods to access our Ubuntu Server using the terminal. In our previous article, we learned how to access our Ubuntu Server using Password authentication. In this demo, we will learn how to access our Ubuntu Server using SSH Public Key.
Before we start this demo, we have already installed Ubuntu Server on Microsoft Azure. Read the previous article to learn the process of installing Ubuntu Server on Azure >> here.
Step 1
Log into your account on Azure Portal here.
In this portal, we have already installed Ubuntu Server named “SL-Ubuntu”.
Step 2
In the "SL-Ubuntu" Server, we can find the Public and Private IP Address.
Step 3
In the “Reset Password” option, we can change our Password-based authentication to reset SSH Public Key. In the Username part, enter your username that you want. In the SSH Public Key field, we need to generate SSH key.
Step 4
We can create the SSH key using “Windows PowerShell”, so run the PowerShell as Administrator.
Step 5
In PowerShell, enter the command “ssh-keygen -t rsa -b 2048” and hit Enter.
Step 6
After running this command in this demo, I don’t enter the specific details.
- Enter File key: just press Enter
- Enter passphrase: just press Enter
- Enter passphrase again: just press Enter
After running the command, there are two files stored in the “Viknaraj” folder - id_rsa and id_rsa.pbu.
Step 7
The “id_rsa.pub” is the SSH key information file. To view the SSH key information, we can use the “cat” command so type “cat C:\Users\Viknaraj\.ssh\id_rsa.pub”, and hit Enter.
Step 8
Here, we can find the SSH key information starting with “ssh-rsa” and the end with a username and PC name. In the demo, it’s “viknaraj@Dell”, so copy the SSH key without space.
Step 9
In the Azure portal, paste the SSH key in the “SSH Public Key” box.
Step 10
After pasting the SSH public key, click “Update” to update the SSH login Information.
Step 11
In the Overview section, we can find the “Connect” button. So, click it. In the "Connect to virtual machine" window, we can find our remote login information. Copy the SSH information under the “Login using VM local account”.
Step 12
In “Windows PowerShell”, paste the login information and hit “Enter”.
Step 13
For the first time authentication, there is one question it will ask - “Are you sure you want to continue the connection? (yes/no)”. Type “Yes” to continue. Now our SL-Ubuntu Server is connected using the SSH key.
Summary
I hope you now understand how to access our Azure Ubuntu Server through SSH Public Key. In this demo, our SL-Ubuntu Server already configured the Password method, so I reset the password to SSH. If you have any questions, feel free to comment under my article.