Last active
February 13, 2023 10:53
-
-
Save kmassada/81938de78714eb4f9166 to your computer and use it in GitHub Desktop.
Quick setup for ssh, and ssh config file
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
# set the variables | |
SSH_HOST="gitlab.com" | |
SSH_USER=`whoami` | |
SSH_PORT=22 | |
# create folder with the correct permissions | |
mkdir -p ~/.ssh/; | |
chmod 700 ~/.ssh/; | |
# generate key with u2f/fido | |
ssh-keygen -t ecdsa-sk -f ~/.ssh/$SSH_USER@$SSH_HOST -b 4096 -P '' -f ~/.ssh/$SSH_USER@$SSH_HOST | |
# OR without | |
# ssh-keygen -t rsa -f $SSH_USER@$SSH_HOST -b 4096 -P ''; | |
## cat into config | |
cat >> ~/.ssh/config << EOF | |
Host $SSH_HOST | |
HostName $SSH_HOST | |
User $SSH_USER | |
IdentityFile ~/.ssh/$SSH_USER@$SSH_HOST | |
Port $SSH_PORT | |
EOF | |
# set the permissions | |
chmod 600 ~/.ssh/config; | |
# copy to instance | |
ssh-copy-id -p $SSH_PORT -i ~/.ssh/$SSH_USER@$SSH_HOST.pub $SSH_USER@$SSH_HOST | |
# OR | |
# ubuntu to clipboard | |
cat ~/.ssh/$SSH_USER@$SSH_HOST.pub | xclip | |
# macos to clipboard | |
cat ~/.ssh/$SSH_USER@$SSH_HOST.pub | pbcopy | |
###### | |
mkdir -p ~/.ssh | |
chmod 700 ~/.ssh | |
touch ~/.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