Created
June 17, 2019 09:17
-
-
Save arthursalvtr/4f797a2659095396f0b8cbc7470094ce to your computer and use it in GitHub Desktop.
Automate Github ssh key and ssh config script
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 | |
echo -e "\nSetting up ssh and config file" | |
if [ ! -d ~/.ssh ]; then | |
echo -e "\nCreating ssh folder" | |
mkdir ~/.ssh | |
else | |
echo -e "\nSSH folder already exists..." | |
fi | |
echo -e "\nGenerating ssh key for github" | |
if [ ! -f ~/.ssh/github ]; then | |
ssh-keygen -t rsa -C "my-server" -b 4096 -N "" -f ~/.ssh/github | |
else | |
echo -e "\nSSH key file already exists..." | |
fi | |
if [ ! -f ~/.ssh/config ]; then | |
echo -e "\nCreating SSH config file" | |
touch ~/.ssh/config | |
chmod 600 ~/.ssh/config | |
else | |
echo -e "\nSSH config file already exists..." | |
fi | |
if ! grep -q 'IdentityFile ~/.ssh/github' ~/.ssh/config; then | |
echo -e "\nAdding github private repo host into ssh config" | |
cat >> ~/.ssh/config << EOL | |
Host github.com | |
IdentityFile ~/.ssh/github | |
EOL | |
chmod 600 ~/.ssh/config | |
echo -e "\nSetting up ssh config permission" | |
else | |
echo -e "\nGithub host config already exists..." | |
fi | |
echo -e "\nSSH key and config file setup completed!" | |
echo -e "\nPlease add these following SSH public key to your github" | |
cat ~/.ssh/github.pub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment