SSH authentication refused bad ownership or modes for file

SSH keys authentication scheme

So you created SSH keypair, installed public key on the server you want to connect to but, probably, made this not as described in this article: How To Set Up SSH Keys and now the server refuses your key and in /var/log/secure we can see message like this:

Authentication refused: bad ownership or modes for file /home/user/.ssh/authorized_keys

or

Authentication refused: bad ownership or modes for directory /home/user/.ssh

or

Permissions 0664 for '/home/user/.ssh/id_ed25519' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/home/user/.ssh/id_ed25519": bad permissions

Correct .SSH directory permissions

The .ssh directory permissions should be 700 (drwx——).  The public key (.pub file) should be 644 (-rw-r–r–). The private key (id_rsa) on the client host, and the authorized_keys file on the server, should be 600 (-rw——-).

To fix .ssh directory and  authorized_keys permissions do the following:

Try to log in again.

Good luck!

Want me to do this for you? Drop me a line: itgalaxyzzz {at} gmail [dot] com