Skip to content

Instantly share code, notes, and snippets.

@DirkHeinke
Last active June 6, 2016 14:34
Show Gist options
  • Save DirkHeinke/3869d04adb68187f1f71ab06a19702ac to your computer and use it in GitHub Desktop.
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.
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