How do I setup Public-Key Authentication for SSH?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you have SSH installed, you should be able to run..
Then go through the steps, you’ll have two files,
id_rsaandid_rsa.pub(the first is your private key, the second is your public key – the one you copy to remote machines)Then, connect to the remote machine you want to login to, to the file
~/.ssh/authorized_keysadd the contents of your thatid_rsa.pubfile.Oh, and
chmod 600all theid_rsa*files (both locally and remote), so no other users can read them:Similarly, ensure the remote
~/.ssh/authorized_keysfile ischmod 600also:Then, when you do
ssh remote.machine, it should ask you for the key’s password, not the remote machine.To make it nicer to use, you can use
ssh-agentto hold the decrypted keys in memory – this means you don’t have to type your keypair’s password every single time. To launch the agent, you run (including the back-tick quotes, which eval the output of thessh-agentcommand)On some distros, ssh-agent is started automatically. If you run
echo $SSH_AUTH_SOCKand it shows a path (probably in /tmp/) it’s already setup, so you can skip the previous command.Then to add your key, you do
and enter your passphrase. It’s stored until you remove it (using the
ssh-add -Dcommand, which removes all keys from the agent)