#On Client: ssh-keygen -t rsa scp ~/.ssh/id_rsa.pub username@hostname:~/.ssh/authorized_keys #On Server (to disable passwords and only allow key) sudo nano /etc/ssh/sshd_config #change "PasswordAuthentication yes" --> "PasswordAuthentication no" #remove "#" in front of the line if present
Here is what the above code is Doing:
1. Generate a key pair on the client machine.
2. Copy the public key to the server.
3. Disable password authentication on the server.
Now, when you try to ssh into the server, you’ll be prompted for the passphrase you set when generating the key pair.
If you want to disable the passphrase, you can do so by running the following command on the client machine:
This will prompt you for the passphrase, and then ask you to enter a new passphrase. Just hit enter to skip the passphrase.