Passwordless SSH improves security and convenience by eliminating the need to store passwords and reducing the risk of password theft. It also speeds up the login process
On your local machine, generate an SSH key:
ssh-keygen -t rsa -b 4096
On Mac OS it will create the following key pair:
~/.ssh/id_rsa
- private key, do not share this!
~/.ssh/id_rsa.pub
- public key
Next, copy the public key to the server:
ssh-copy-id user@your_server_ip
If the ssh-copy-id
command is not available, you can also do it manually:
cat ~/.ssh/id_rsa.pub | ssh user@your_server_ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Now try to login without a password:
ssh user@your_server_ip
If everything works correctly, you can disable password authentication. For this, edit the SSH configuration on your server:
sudo nano /etc/ssh/sshd_config
Find the following lines and modify them (or add them if they don't exist):
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no
After saving the file, restart the SSH service:
sudo systemctl restart sshd