ssh “permissions are too open” error

2019-01-03 19:19发布

I had a problem with my mac where I couldn't save any kind of file on the disk anymore. I had to reboot OSX lion and reset the permissions on files and acls.

But now when I want to commit a repository I get the following error from ssh:

Permissions 0777 for '/Users/username/.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.

What permissions levels should i give to the id_rsa file?

15条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-03 19:35

Intersting message here. Operating Syatems are smart enough to deny remote connections if your private key is too open. It understands the risk where permissions for id_rsa is wide open (read, is edittable by anyone).

{ One might have changed your lock first and then open it with the keys he already had. }

cd ~/.ssh
chmod 400 id_rsa

PS:

While working on the multiple servers (non-production), most of us feel need to connect remote server with ssh. A good idea is to have a pice of application level code (may be java using jsch) to create ssh trusts between servers. This way connection will be passwordless. Incase, perl is installed - one may use net ssh module too.

查看更多
一纸荒年 Trace。
3楼-- · 2019-01-03 19:36

Keys need to be only readable by you:

chmod 400 ~/.ssh/id_rsa

600 appears to be fine as well (in fact better in most cases, because you don't need to change file permissions to edit it).

The relevant portion from the manpage (man ssh)

 ~/.ssh/id_rsa
         Contains the private key for authentication.  These files contain sensitive 
         data and should be readable by the user but not
         accessible by others (read/write/execute).  ssh will simply ignore a private 
         key file if it is              
         accessible by others.  It is possible to specify a
         passphrase when generating the key which will be used to encrypt the sensitive 
         part of this file using 3DES.

 ~/.ssh/identity.pub
 ~/.ssh/id_dsa.pub
 ~/.ssh/id_ecdsa.pub
 ~/.ssh/id_rsa.pub
         Contains the public key for authentication.  These files are not sensitive and 
         can (but need not) be readable by anyone.
查看更多
家丑人穷心不美
4楼-- · 2019-01-03 19:43

provide 400 permission, execute below command

chmod 400 /Users/username/.ssh/id_rsa

enter image description here

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-01-03 19:44

The locale-independent solution that works on Windows 8.1 is:

chgrp 545 ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa

GID 545 is a special ID that always refers to the 'Users' group, even if you locale uses a different word for Users.

查看更多
孤傲高冷的网名
6楼-- · 2019-01-03 19:44

There is one exception to the "0x00" permissions requirement on a key. If the key is owned by root and group-owned by a group with users in it, then it can be "0440" and any user in that group can use the key.

I believe this will work with any permissions in the set "0xx0" but I haven't tested every combination with every version. I have tried 0660 with 5.3p1-84 on CentOS 6, and the group not the primary group of the user but a secondary group, and it works fine.

This would typically not be done for someone's personal key, but for a key used for automation, in a situation where you don't want the application to be able to mess with the key.

Similar rules apply to the .ssh directory restrictions.

查看更多
劫难
7楼-- · 2019-01-03 19:44

I have came across with this error while I was playing with Ansible. I have changed the permissions of the private key to 600 in order to solve this problem. And it worked!

chmod 600 .vagrant/machines/default/virtualbox/private_key
查看更多
登录 后发表回答