Last active
January 16, 2020 04:38
-
-
Save samsargent/4e6dea633ac3075dab87 to your computer and use it in GitHub Desktop.
SSH Login - No Password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IP=$(curl -Sfs https://wtfismyip.com/text) && KEY=$(cat ~/.ssh/id_rsa.pub) && echo 'from="'$IP'"' $KEY | ssh user@host 'cat >> ~/.ssh/authorized_keys' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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