SSH connection with authentication using public key cryptography
Contents
Creation of public and private key pairs
Create a public/private key pair for a user connecting to the Linux server using OpenSSH.
Use ssh-keygen to create key pairs.
Creation of public/private key pairs is performed with remote login user privileges。
If you do not specify the destination and file name, id_ed25519 and id_ed25519.pub will be created in /home/(user name)/.ssh/. On the way, enter the password for the key.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# su - huong [huong@Lepard~]$ ssh-keygen -t ed25519 Generating public/private ed25519 key pair. Enter file in which to save the key (/home/huong/.ssh/id_ed25519): Created directory '/home/huong/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/huong/.ssh/id_ed25519 Your public key has been saved in /home/huong/.ssh/id_ed25519.pub The key fingerprint is: SHA256:Yq9/XCRZ6jjImkPg2FvzwFaAHaIiaoZGmMUVq6uYo18 huong@Lepard The key's randomart image is: +--[ED25519 256]--+ | .o++o | |.+o.o. . | |*. .. + | |* .. . + . | |oB.o oo.So o | |= o.B.ooo . . | | .=E* .o . | |oo..+ .. o | |*o. ..... | +----[SHA256]-----+ |
1 2 3 |
$ cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys $ chmod 600 ~/.ssh/authorized_keys $ chmod 700 ~/.ssh/ |
Save the created private key id_ed25519 to an appropriate location on windows using winSCP.
Start Winscp
Host name : Server IP Address
Port number : SSH port number
User name : Server Login User
Password : Password for the same user
Click "Save"
![](https://korodes.com/wp-content/uploads/2023/10/261a6cdb089a39ae4225899b9ef026bf.png)
Site name : Any name
Click "OK
![](https://korodes.com/wp-content/uploads/2023/10/003ca88bbe7cdfdb4f17ddee3a01826b.png)
After confirming the server, click "Login".
![](https://korodes.com/wp-content/uploads/2023/10/7ae5046c17bfbd887ff36dec11bf3147.png)
Click "Update" when the following screen appears
![](https://korodes.com/wp-content/uploads/2023/10/e097b00d4ba591e92a286f2d1dc73a3a.png)
Password of the logged-in user in the Password field
![](https://korodes.com/wp-content/uploads/2023/10/50e66ad9b9d2ff2a7abdf4484a3462f5.png)
When connected, the right column is the server side and the left column is the PC (Windows) side.
Save the file "id_ed25519" in the .ssh directory to an appropriate location on Windows in the left column.
![](https://korodes.com/wp-content/uploads/2023/10/4a10df8b682497539c735598b2bd95ce.png)
Editing SSH Configuration File
Edit the SSH configuration file to disable password authentication.
This time, instead of being an ordinary user, su - to become root.
1 2 3 4 5 6 7 |
$ su - Password: # vi /etc/ssh/sshd_config # Line 66 : Changed to no password authentication PasswordAuthentication no # systemctl restart sshd |
How to connect with Tera Term
Start Tera Term, and select "File" menu "New connection"
![](https://korodes.com/wp-content/uploads/2023/10/f73125b4d05be6e22cf312b3221a6b0c.png)
Host : Server IP Address
TCP port : SSH port number
If you get the following security warning Check "Replace...." and click "Continue".
![](https://korodes.com/wp-content/uploads/2023/10/7ec721234f7a13ed5918bd58a4fd877d.png)
User name : Login User Name
Password : Password specified in the creation of a public/private key pair
Under "Use RSA/DSA/ECDSA/ED25519 key to log in", set "Private key file:" to "id_ed25519" that you just saved in Windows. and click "OK".
![](https://korodes.com/wp-content/uploads/2023/10/ac8380005b21df9251e2cb092fdebafb.png)
Creating a private key using PuTTYgen
Start Winscp and launch [Run Puttygen] from [Tools].
Select the appropriate server
![](https://korodes.com/wp-content/uploads/2023/10/6e5fccc17754535f44e4a44106a31d4f.png)
Click Load
![](https://korodes.com/wp-content/uploads/2023/10/d50aa48bd915489d1efb5cd0f6714c1f.png)
The [ Open File Dialog ] will open, change the file type to [ All Files (*. Change the file type to [ All Files (*. *) ] and load the private key id_ed25519 that was transferred from the Linux server.
![](https://korodes.com/wp-content/uploads/2023/10/43d8b291dedd7481ea3984b6b78d61f9.png)
The password is the password set in "Creating a public and private key pair" above
![](https://korodes.com/wp-content/uploads/2023/10/076a63731f3294fb98d6af6ebfc008a1.png)
![](https://korodes.com/wp-content/uploads/2023/10/90f7e470543e24439e4890303b68bcff.png)
Click on "Save private key"
![](https://korodes.com/wp-content/uploads/2023/10/c0e2f243c22599b61a198f90d59842b9.png)
Save the file with the extension ".pppk" in the same place as "id_ed25519" saved earlier on the Windows side under the name "id_ed25519.pppk".
![](https://korodes.com/wp-content/uploads/2023/10/f7d3ed46f107ed392b0f0780e8d92a95.png)
Select the appropriate server and click "Edit"
![](https://korodes.com/wp-content/uploads/2023/10/d248e2860b91b12dccc8d69d9f30c8e8.png)
Click on "Advanced"
![](https://korodes.com/wp-content/uploads/2023/10/57adc36ef307805d8a5c29f17964c6b5.png)
Open the "Authentication" menu and specify "id_ed25519.ppk" saved in Windows for "Private key file
![](https://korodes.com/wp-content/uploads/2023/10/152669a1f2d0b33996d6e551d2ab1872.png)
Click "Save"
![](https://korodes.com/wp-content/uploads/2023/10/6b9d4688ca814e62e8a690234a73e679.png)
Click on "Login"
![](https://korodes.com/wp-content/uploads/2023/10/15e4d85723c9e745faec937adfb4a062.png)
The password is the password set in "Creating a public and private key pair" above
![](https://korodes.com/wp-content/uploads/2023/10/e6970418cc25e63580f530297143904c.png)
When connecting with Tera Term, use the following
Use RSA/DSA/ECDSA/..." Specify "id_ed25519.ppk" saved in windows in the "Use RSA/DSA/ECDSA/..." field.
![](https://korodes.com/wp-content/uploads/2023/10/086861ad0f0f3f9fd596b0e4ddc9694f.png)