Get your SSH public key – with from IP prepended – ready to add to the authorized_keys file of a server you want to log into without a password.
IP=$(curl -Sfs https://wtfismyip.com/text) && KEY=$(cat ~/.ssh/id_rsa.pub) && echo 'from="'$IP'"' $KEY
Go one step further and add it to the server automatically:
IP=$(curl -Sfs https://wtfismyip.com/text) && KEY=$(cat ~/.ssh/id_rsa.pub) && echo 'from="'$IP'"' $KEY | ssh user@host 'cat >> ~/.ssh/authorized_keys'
I’ve noticed, depending on the server and permissions 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
Just turned it into a bash script that will prompt for the username & host and do the rest for you.
https://gist.github.com/samsargent/4e6dea633ac3075dab87