Last active
June 6, 2016 14:34
-
-
Save DirkHeinke/3869d04adb68187f1f71ab06a19702ac to your computer and use it in GitHub Desktop.
Append your id_rsa.pub to the authorized_keys of the root user via sudo.
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
echo "Remote Server (e.g. example.com)" | |
read remote_server | |
# test if login already possible | |
ssh -q -o ConnectTimeout=3 -o PasswordAuthentication=no root@$remote_server echo "" > /dev/null | |
if [ $? -eq 0 ] | |
then | |
echo "You can already login!" | |
exit | |
fi | |
pub_key=`cat ~/.ssh/id_rsa.pub` | |
command='sudo mkdir -p /root/.ssh ; echo '$pub_key' | sudo tee --append /root/.ssh/authorized_keys > /dev/null' | |
ssh -t $remote_server "$command" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment