Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SSH Login - No Password
#!/bin/bash
echo "Enter ssh username & host you want to add your key to in the following format: username@host.com"
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

This comment has been minimized.

Copy link
Owner Author

samsargent commented Jul 29, 2015

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
You can’t perform that action at this time.