Created
June 7, 2017 21:40
-
-
Save jasmas/fad0ee3fca34763378bf89023abac216 to your computer and use it in GitHub Desktop.
ssh-send-key
This file contains 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 | |
[ -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