Configuring SSH Key-based Authentication
Configuring Public and Private Keys on Linux
- Use an SSH tool to remotely log in to the Linux CLI as the OS user.
Perform this step as the root user. If you log in as a common user, run the su command to switch to the root user.
- Create a public-private key pair.
1ssh-keygen -t rsa -b 4096
During the process, perform the following operations:
- (Optional) Enter the key file names. By default, the id_rsa file (private key file) and id_rsa.pub file (
public key file) are saved in the /root/.ssh/id_rsa directory. - (Optional) Set the password of the key.
The following information is displayed:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa already exists. Overwrite (y/n)? y Enter passphrase (empty for no passphrase): Enter same passphrase again: 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:g8T/XaRUqANpuIjxnI34In89+R68QckZPw7eyEaCU+o root@host11 The key's randomart image is: +---[RSA 4096]----+ | . . .. | | . .. + .. | | * =+o.. .. . | | o *=o+ =o. o | | .+ o S o.. . | |. .... B B o . | | o .E. .O + . | | . . +. + | | . ++ | +----[SHA256]-----+
- (Optional) Enter the key file names. By default, the id_rsa file (private key file) and id_rsa.pub file (
- Upload the public key file to the node server.
1ssh-copy-id -i /root/.ssh/id_rsa.pub root@Server IP
- /root/.ssh/id_rsa.pub is the generated public key file, and Server_IP is the IP address of the node server. Replace them with the actual values.
- The uploaded public key file is stored in the /root/.ssh directory by default. If you log in as a common user, upload the file to the directory of the corresponding user name and replace root in the command with the common user name.
During the process, enter the password of the node server user.
- Copy the private key file to the /home/devkit directory.
1cp /root/.ssh/id_rsa /home/devkit
- Configure the permission of the devkit user.
1chown devkit:devkit /home/devkit/id_rsa
Parent topic: Common Operations