Skip to content

Instantly share code, notes, and snippets.

@luiscoms
Last active August 29, 2015 14:02
Show Gist options
  • Save luiscoms/d41b04a5ae79a05f6cc0 to your computer and use it in GitHub Desktop.
Save luiscoms/d41b04a5ae79a05f6cc0 to your computer and use it in GitHub Desktop.
Generate and copy ssh publickey to remote host
#!/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"
@luiscoms
Copy link
Author

I found this command

ssh-copy-id -i ~/.ssh/id_dsa $REMOTEUSER@REMOTEHOST

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment