How to fix “WARNING: UNPROTECTED PRIVATE KEY FILE!” on Linux

WARNING: UNPROTECTED PRIVATE KEY FILE! Permissions 0744 for '/home/user/.ssh/id_rsa' are too open. It is recommended that your private key files are NOT accessible by others. This private key will be ignored. bad permissions: ignore key: /home/user/

If you are getting this error then you probably reset the permissions on your hidden .ssh directory in your user folder, and your keys aren’t going to work anymore. It’s very important that these files not be writable by just anybody with a login to the box, so openssh will give you an error if you try to use them.

To fix this, you’ll need to reset the permissions back to default:

sudo chmod 600 ~/.ssh/id_rsa
sudo chmod 600 ~/.ssh/id_rsa.pub

If you get another error:

Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/user/.ssh/known_hosts)

Adjust the permissions on that file with:

sudo chmod 644 ~/.ssh/known_hosts

Finally, you may need to adjust the directory permissions as well.

sudo chmod 755 ~/.ssh