Created
September 2, 2015 17:46
-
-
Save rtvenge/57eea5e71bbb0979b5df to your computer and use it in GitHub Desktop.
Create an SSH shortcut and key shell script.
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 | |
echo "Please enter username on server: " | |
read USER | |
echo "Please enter server host or IP address (ex: opticllc.com)" | |
read SERVER_HOST | |
echo "Please enter server name (aka ssh shortcut)" | |
read SERVER_NAME | |
# USER="rtvenge" | |
# SERVER_NAME="ryantvenge.com" | |
# add shortcut to ssh config file | |
echo -e "Host $USER \n HostName $SERVER_HOST \n Port 22 \n User $USER \n IdentityFile ~/.ssh/$USER" >> ~/.ssh/config | |
# Try to create an ssh directory and create authorized_keys file on server | |
ssh $SERVER_NAME 'mkdir ~/.ssh && touch ~/.ssh/authorized_keys' | |
# create ssh key | |
ssh-keygen -f ~/.ssh/$USER -C "$SERVER_NAME" | | |
# wait for ssh-keygen to complete | |
wait | |
# ssh into server and copy ssh key up | |
cat ~/.ssh/$USER.pub | ssh $USER 'cat >> .ssh/authorized_keys' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment