Skip to content

Instantly share code, notes, and snippets.

@jasmas
Created June 7, 2017 21:40
Show Gist options
  • Save jasmas/fad0ee3fca34763378bf89023abac216 to your computer and use it in GitHub Desktop.
Save jasmas/fad0ee3fca34763378bf89023abac216 to your computer and use it in GitHub Desktop.
ssh-send-key
#!/bin/bash
[ -z $1 ] && echo 'usage: ssh-send-key [user@]hostname' && exit 1
KEY=`ssh-add -L` #set to, e.g., `cat ~/.ssh/id_rsa.pub` if not using agent
read -r -d '' CMDS << END
[ ! -d .ssh ] && mkdir .ssh && chmod 700 .ssh
[ ! -f .ssh/authorized_keys2 ] && touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
echo "$KEY" >> .ssh/authorized_keys
chmod 400 .ssh/authorized_keys
END
echo "$CMDS" | ssh $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment