Last active
August 29, 2015 14:02
-
-
Save luiscoms/d41b04a5ae79a05f6cc0 to your computer and use it in GitHub Desktop.
Generate and copy ssh publickey to remote host
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
#!/bin/bash | |
# replace config | |
REMOTEUSER="luiscoms" | |
REMOTEHOST="example.com" | |
# generate ssh key if not exits | |
if [ ! -f ~/.ssh/id_dsa.pub ];then | |
ssh-keygen -t dsa | |
fi | |
# create if not exists .ssh directory | |
# copy the public key to remote host | |
ssh $REMOTEUSER@$REMOTEHOST "mkdir -p ~/.ssh; chmod 700 ~/.ssh/; echo `cat ~/.ssh/id_dsa.pub` >> ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found this command