Skip to content

Instantly share code, notes, and snippets.

@kmassada
Last active February 13, 2023 10:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmassada/81938de78714eb4f9166 to your computer and use it in GitHub Desktop.
Save kmassada/81938de78714eb4f9166 to your computer and use it in GitHub Desktop.
Quick setup for ssh, and ssh config file
# 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