if ((st.st_uid == getuid()) && (st.st_mode & 077) != 0) {
error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
error("@ WARNING: UNPROTECTED PRIVATE KEY FILE! @");
error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
error("Permissions 0%3.3o for '%s' are too open.",
(u_int)st.st_mode & 0777, filename);
error("It is required that your private key files are NOT accessible by others.");
error("This private key will be ignored.");
return SSH_ERR_KEY_BAD_PERMISSIONS;
If changing the permissions of the key file is not an option, a solution is to download the OpenSSH source, remove that check from the code and rebuild it.
–
An answer to a related question suggests there is no way to bypass the permissions check.
However, I had the same problem ---
I wanted several users to share the same key to be able to access and control a large group of hosts ---
and my fix might be useful to others.
Here's what I did:
Create a special user (say, master
) and group (master
) to hold the key.
Create/store the key files in ~master/.ssh/
.
Give group read permissions to the key file, chmod g+r ~master/.ssh/id_rsa
.
Add each of the authorized users to the master
group.
Make a link from ~user/.ssh/id_rsa
to ~master/.ssh/id_rsa
.
This allows the authorized user to ssh
without problems,
but avoids opening up the key to everyone.
Also, the key owner is not root.
Strangely, the master
user itself will still get the "unprotected private key" warning.
This can be circumvented by changing the owner (but not the group) of the key file to some special user that will never need to use the key,
sudo chown daemon ~master/.ssh/id_rsa
, for instance.
–
–
–
–
You could make it available for raeding with Access Control Lists. Use the utilities getfacl
and setfacl
.
Remember to also set a proper mask with setfacl
, because normally any separate permissions you will add won't be effective if the group permissions aren't the same.
Your file system needs to support it, though. If it's not enabled, you have to add the mount option in your fstab.
–
–
As everyone suggests there is no way to bypass the security checks.
But you can create a copy of the key and change the permissions on this key:
# Copy your key to a new location
cp <<your_key>> <<new_key>>
# Make sure you are the owner
chown <<your_user>>:<<your_user>> <<new_key>>
# Give yourself the full permissions while removing all access for others
chmod 700 <<new_key>>
It worked for me.
–
The comment from @João Rodrigues to the answer from @Andrei Savin gives at the end a hint for me using sudo:
sudo -u nobody ssh -i <path to identity file> <ssh server>
The following error messages (examples)
Could not create directory '/var/empty/.ssh'.
The authenticity of host 'xxx' can't be established.
ECDSA key fingerprint is SHA256:yyy.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Failed to add the host to the list of known hosts (/var/empty/.ssh/known_hosts).
could be ignored. It works out-of-the-box using Debian Buster (OpenSSH_7.9p1, OpenSSL 1.1.1d) and MacOS Big Sur (OpenSSH_8.1p1, LibreSSL 2.7.3).
A suggestion from a different perspective:
SSH works with a file (usually ~/.ssh/authorized_keys, if you have access to the file system of the server) to decide what key pairs to allow to be used for an account.
If you can edit this file, just append the public key from each user to this file for the account in question, and they all will be allowed to log on to this account. If someone quits or changes job description, remove their pubkey from the file.