Skip to content

Instantly share code, notes, and snippets.

@denisgolius
Forked from grenade/01-generate-ed25519-ssh-key.sh
Created October 4, 2018 06:55
Show Gist options
  • Star 75 You must be signed in to star a gist
  • Fork 30 You must be signed in to fork a gist
  • Save denisgolius/d846af3ad5ce661dbca0335ec35e3d39 to your computer and use it in GitHub Desktop.
Save denisgolius/d846af3ad5ce661dbca0335ec35e3d39 to your computer and use it in GitHub Desktop.
Correct file permissions for ssh keys and config.
ssh-keygen -t rsa -b 4096 -N '' -C "rthijssen@gmail.com" -f ~/.ssh/id_rsa
ssh-keygen -t rsa -b 4096 -N '' -C "rthijssen@gmail.com" -f ~/.ssh/github_rsa
ssh-keygen -t rsa -b 4096 -N '' -C "rthijssen@gmail.com" -f ~/.ssh/mozilla_rsa
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/github_rsa
ssh-add ~/.ssh/mozilla_rsa
chmod 700 ~/.ssh
chmod 644 ~/.ssh/authorized_keys
chmod 644 ~/.ssh/known_hosts
chmod 644 ~/.ssh/config
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
chmod 600 ~/.ssh/github_rsa
chmod 644 ~/.ssh/github_rsa.pub
chmod 600 ~/.ssh/mozilla_rsa
chmod 644 ~/.ssh/mozilla_rsa.pub
@spex66
Copy link

spex66 commented Nov 8, 2022

thx for the handy list!

In case you copy/pasted the .ssh folder from somewhere, following might be required to change owner recursive (-R) for the whole .ssh folder

# replace 'username' through your account :)
sudo chown -R username:username ~/.ssh

@denisgolius
Copy link
Author

# replace 'username' through your account :)
sudo chown -R username:username ~/.ssh

the original gist have those suggestion https://gist.github.com/grenade/6318301?permalink_comment_id=3289864#gistcomment-3289864

@bumbummen99
Copy link

bumbummen99 commented Jul 16, 2023

# Fix directory permissions
chmod 700 ~/.ssh

# Fix all key permissions
chmod 600 ~/.ssh/*
chmod 644 ~/.ssh/*.pub

# Fix special files permissions
chmod 644 ~/.ssh/authorized_keys
chmod 644 ~/.ssh/known_hosts
chmod 644 ~/.ssh/config

For copy and paste:

chmod 700 ~/.ssh && \
chmod 600 ~/.ssh/* && \
chmod 644 -f ~/.ssh/*.pub ~/.ssh/authorized_keys ~/.ssh/known_hosts ~/.ssh/config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment