Skip to content

Instantly share code, notes, and snippets.

@sukobuto
Last active October 1, 2018 06:32
Show Gist options
  • Save sukobuto/469269891536ed6cedcc0e79318315f7 to your computer and use it in GitHub Desktop.
Save sukobuto/469269891536ed6cedcc0e79318315f7 to your computer and use it in GitHub Desktop.
Generate deploy key on server
#!/bin/bash
keyname=$1
if [ $# -lt 1 ]
then
echo "usage: ./github_deploy_key.sh <keyname>"
exit 1
fi
expect -c "
set timeout 5
spawn ssh-keygen -t rsa -f .ssh/github_${keyname}
expect \": \"
send \"\n\"
expect \"Enter passphrase (empty for no passphrase): \"
send \"\n\"
expect \"Enter same passphrase again: \"
send \"\n\"
wait
"
echo -e "\n\n===== usage ====="
echo "git clone github_${keyname}:<user or org>/<rep name>"
echo -e "\n===== copy & paste into github deploy key ====="
cat << EOS >> .ssh/config
Host github_${keyname}
HostName github.com
Port 22
User git
IdentityFile ~/.ssh/github_${keyname}
EOS
cat .ssh/github_${keyname}.pub
@sukobuto
Copy link
Author

sukobuto commented Sep 7, 2018

usage:

install requirements

sudo apt-get install expect

download

cd ~
wget https://gist.githubusercontent.com/sukobuto/469269891536ed6cedcc0e79318315f7/raw/7ad9e2151ff3990de03b521db087ac9cc379b50b/github_deploy_key.sh && chmod +x github_deploy_key.sh

use

cd ~
./github_deploy_key.sh <name>

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