Passwordless login to Linux through SSH public and private keys on Windows
-
Generate an SSH key pair on Windows:
-
Open a command prompt or PowerShell window.
-
Enter the following command to generate an SSH key pair:
ssh-keygen -t rsa -b 4096
-
Follow the prompts to enter the key storage path and password (optional).
-
The public key file (with .pub as suffix) and private key file (without suffix) will be generated under the specified path.
-
-
Copy the public key to the Linux server:
-
Copy the generated public key file (for example
id_rsa.pub
) to your Linux server. -
Copy the public key file to your Linux server using the SCP command, for example:
scp id_rsa.pub username@linux_server_ip:~/.ssh/authorized_keys
-
This will copy the public key file to
~/.ssh/authorized_keys
a file on the Linux server.
-
-
Configure Linux server permissions:
-
On a Linux server, make sure
~/.ssh
the permissions of the directory are set to 700 with the command:chmod 700 ~/.ssh
-
Then, make sure
~/.ssh/authorized_keys
the permissions of the file are set to 600, the command is:chmod 600 ~/.ssh/authorized_keys
-
-
Try logging in without a password:
-
You should now be able to connect to your Linux server using SSH from your local computer on Windows without entering a password.
-
From a Windows Command Prompt or PowerShell window, use the following command to connect to your Linux server:
ssh username@linux_server_ip
-
If everything is set up correctly, you will be able to log in directly to your Linux server without entering a password.
-