How to configure SSH for a passwordless login into your remote machine
Published: Jan 26, 2024
- On local machine, run
ssh-keygen
- This creates two files
/.ssh/id_rsa.pub(public key) and/.ssh/id_rsa(private key). - Still on local machine, run
ssh-copy-id remoteusername@remoteserver
- This copies your public key to remote server.
- Now try doing ssh to remote machine, no password should be required.
if ssh-copy-id fails
Sometimes, ssh-copy-id gives an error and doesn’t copy the files. In that case, use this one liner but replace the remoteuser and servername:
cat ~/.ssh/id_rsa.pub | ssh remoteusername@remoteserver "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
Ensure
- Remote machine is running sshd.
- Local machine has relevant terminal with ssh installed.
❗