Linux configuration SSH password-free login tutorial.

To configure SSH password-free login on Linux, you can follow the steps below:

Step 1: Generate a key pair
Generate a key pair on the local computer, one is a private key (private key), and the other is a public key (public key). Execute the following command on the terminal:

ssh-keygen -t rsa

This command will generate an RSA type key pair. Follow the prompts to choose where the key is saved and set an optional passphrase.

Step 2: Copy the public key to the target server
Use the following command to copy the public key to the target server, replacing  <remote_username>and  <remote_server>with the username and IP address of the target server:

ssh-copy-id <remote_username>@<remote_server>

This command copies the public key on the local computer to  ~/.ssh/authorized_keysa file on the target server. You may need to enter the target server's password for confirmation.

Step 3: Test passwordless login
Now, you can try to use SSH for passwordless login. Execute the following command on the terminal, replacing  <remote_username>and  <remote_server>with the username and IP address of the target server:

ssh <remote_username>@<remote_server>

If everything is set up correctly, you will be logged in directly to the target server without entering a password.

Step 4: Optional Configurations
If you want to further strengthen security, you can perform some optional configurations.

/etc/ssh/sshd_configFirst, make sure the following lines are in the correct state in the file on the target server  :

PubkeyAuthentication yes
PasswordAuthentication no

Then, restart the SSH service for the changes to take effect:

sudo service ssh restart

This way, SSH will only allow authentication using public keys, disallowing password logins.

Additionally, if your keys are saved in a non-default location, you can  ~/.ssh/configspecify the location of the keys by adding the following line to a file on your local computer:

Host <remote_server>
    IdentityFile /path/to/private_key

In the above configuration,  <remote_server>replace the IP address or hostname of the target server with  /path/to/private_keythe path to your private key file.

The above is a brief Linux configuration SSH password-free login tutorial. The specific configuration may vary depending on the operating system version and security policy, and you can adjust and expand it according to the actual situation. If you need more detailed steps and configuration options, it is recommended to refer to the official documentation or other authoritative tutorial resources.

Guess you like

Origin blog.csdn.net/tiansyun/article/details/132039920