step-by-step guide to setting up SSH passwordless login¶
Step 1: Generate SSH Keys on Client¶
On the Client Machine¶
Run the following command to generate SSH keys:
This will create a pair of files: id_rsa (private key) and id_rsa.pub (public key).
Step 2: Copy Public Key to Server¶
Using SSH-Copy-ID¶
Run the following command to copy the public key to the server:
Replace username with your actual username and server_ip with the IP address of your server.
Manual Method¶
If ssh-copy-id is not available, you can copy the public key manually:
Then, log in to the server and append the public key to the authorized_keys file:
Alternative way of adding keys¶
Add GitHub user public keys to authorized_keys¶
If you want to add all public keys for a GitHub user (convenient for provisioning accounts), GitHub exposes them at https://github.com/<username>.keys. (no login required)
Local (on the server) using curl:
Local (on the server) using wget:
Remote (from your client) using ssh + curl:
Remote (from your client) using ssh + wget:
Replace GITHUB_USERNAME with the GitHub account name whose public keys you want to add. These commands create the .ssh folder if missing and set safe permissions.
Step 3: Configure SSH Server¶
Edit SSHD Config¶
Edit the SSH server configuration file (usually /etc/ssh/sshd_config) and ensure the following lines are uncommented:
Restart the SSH server to apply changes:
Step 4: Test Passwordless Login¶
Connect to Server¶
Try connecting to the server using SSH:
You should be logged in without being prompted for a password.