I used to make an SSH connection to an AWS server, but when I ran CentOS in a local development environment, I made a note of it because I needed to create a key and so on.
Server side CentOS8.2 Client side Windows 10 (SSH client software VSCode)
-Remote-SSH is installed in VS Code Reference: Develop on EC2 using VSCode's Remote --SSH function -Tar is installed on the server
① Create a private key / public key on the server side ② Upload the private key to the client side ③ SSH connection to the server with VS Code
It seems that the creation of the private key / public key is mechanically done on the server side or the client side, but it seems that it is more common to transfer the public key created on the client side to the server side. This time, I wanted to create a key on Linux, so I will create it on the server side (CentOS).
Create private / public key
# ssh-keygen -t RSA -b 4096
Generating public/private RSA key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
ssh-keygen
is a command to create a private key and a public key.
Format ssh-keygen -t encryption method -b number of bits
Option -t
Specify encryption method
-b
Specify the number of bits
If you did not specify a location with the -f option, you will be asked if you want to save it in /root/.ssh/id_rsa and press ENTER. You will be prompted to enter the passphrase to set as the private key, just press Enter without it.
Creation completed
# ssh-keygen -t RSA -b 4096
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:7YG9R04q702Nje8GSOEH7kdrgrsgrsgLYbTqNTbWvU [email protected]
The key's randomart image is:
+---[RSA 4096]----+
| |
| .+ .. . o |
| .+.=..+ o o |
|.. o++. o++ . |
|. ooo. SE+oo |
| o .+o .oB.= |
| +o. . + *.o |
| .o o + .. |
| .. . .o .oo |
+----[SHA256]-----+
~/.ssh/Make sure the key is created in
# ls -al ~/.ssh/
-rw-------.1 root root 3389 November 3 01:08 id_rsa
-rw-r--r--.1 root root 752 November 3 01:08 id_rsa.pub
Modify the public key filename to authorized_keys.
Authorized public key filename_Fixed to keys
# mv id_rsa.pub authorized_keys
This completes the public and private key generation. Then move the private key to the client side.
You can use the scp command, but this time I moved it to the client side using the function of Teraterm.
File→SSH_SCP
From /root/.ssh/id_rsa
To any Windows folder
Reference: How to easily transfer files with Teraterm without using commands
Click on the monitor-like icon in the left pane of VS Code
Since the remote explorer opens, press + on the right side of SSH TARGETS
The command input screen opens, so enter the following
ssh -l root -i" Private key path in Windows folder "Ssh server host name or IP address
Press Enter to complete the connection.
SSH
is a command to connect to another host using the ssh protocol.
Format ssh option host name
Option -l
Specify user
-i
Specify the private key
Recommended Posts