Skip to content

Instantly share code, notes, and snippets.

@samsargent
Last active January 16, 2020 04:38
Show Gist options
  • Save samsargent/4e6dea633ac3075dab87 to your computer and use it in GitHub Desktop.
Save samsargent/4e6dea633ac3075dab87 to your computer and use it in GitHub Desktop.
SSH Login - No Password
#!/bin/bash
echo "Enter ssh username & host you want to add your key to in the following format: [email protected]"
read host
IP=$(curl -Sfs https://wtfismyip.com/text)
KEY=$(cat ~/.ssh/id_rsa.pub)
echo 'Adding Key to '$host': from="'$IP'"' $KEY
echo 'from="'$IP'"' $KEY | ssh $host 'cat >> ~/.ssh/authorized_keys'
exit;
IP=$(curl -Sfs https://wtfismyip.com/text) && KEY=$(cat ~/.ssh/id_rsa.pub) && echo 'from="'$IP'"' $KEY | ssh user@host 'cat >> ~/.ssh/authorized_keys'
@samsargent
Copy link
Author

Sometime this doesn't work and you still need to enter a password..

Try the following:

Put the public key in .ssh/authorized_keys2 mv authorized_keys authorized_keys2
Change the permissions of .ssh to 700 chmod 700 .ssh
Change the permissions of .ssh/authorized_keys2 to 640 chmod 640 authorized_keys2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment