Skip to content

Instantly share code, notes, and snippets.

@lmgeorge
Last active March 25, 2024 17:07
Show Gist options
  • Save lmgeorge/4563fee4f5b382301c5997aa0010f9c0 to your computer and use it in GitHub Desktop.
Save lmgeorge/4563fee4f5b382301c5997aa0010f9c0 to your computer and use it in GitHub Desktop.
Generate ssh keys for a new machine
#!/bin/bash
mkdir ~/.ssh
touch ~/.ssh/authorized_keys
touch ~/.ssh/known_hosts
cat <<EOF > ~/.ssh/config
Host *
User ${USER}
IdentityFile ~/.ssh/host.key
Host github.com
HostName github.com
User git
IdentitiesOnly yes
IdentityFile ~/.ssh/github.key
EOF
ssh-keygen -t rsa -b 4096 -N '' -f ~/.ssh/host.key
ssh-keygen -t rsa -b 4096 -N '' -f ~/.ssh/github.key
# Set permissions
chmod 700 ~/.ssh
chmod 644 ~/.ssh/*
chmod 600 -f ~/.ssh/*.key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment