我从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.

我应该授予id_rsa文件什么权限?


当前回答

我用sudo成功了

sudo chmod 400 pem-file.pem
sudo ssh -i pem-file.pem username@X.X.X.X

其他回答

我尝试了对我的私钥进行600级的权限,结果成功了。

chmod 600 privateKey 
[dev]$ ssh -i privateKey user@ip

另一方面

chmod 755 privateKey 
[dev]$ ssh -i privateKey user@ip

给出以下问题:

Permissions 0755 for 'privateKey' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "privateKey": bad permissions

密钥只需由您读写:

chmod 600 ~/.ssh/id_rsa

或者,密钥只能由您读取(这也会阻止您的写访问):

chmod 400 ~/.ssh/id_rsa

600在大多数情况下似乎更好,因为您不需要稍后更改文件权限来编辑它

手册页中的相关部分(man-ssh)

~/.ssh/id_rsa包含用于身份验证的私钥。这些文件包含敏感数据,用户应能阅读,但不能其他人可以访问(读/写/执行)。ssh只会忽略私有密钥文件(如果是)其他人可以访问。可以指定生成将用于加密敏感密钥的密钥时的密码短语此文件的一部分使用3DES。~/.ssh/identity.pub~/.ssh/id_dsa.pub~/.ssh/id_ecdsa.pub~/.ssh/id_rsa.pub包含用于身份验证的公钥。这些文件不敏感任何人都可以(但不需要)阅读。

提供400许可,执行以下命令

chmod 400 /Users/username/.ssh/id_rsa

正如人们所说的,在Windows中,我只是将.pem文件放在C:\Users\[user]\.ssh\中,这就解决了问题。尽管您可以在bash或powershell提示符下执行chmod和其他命令行选项,但这些选项都不起作用。我没有改变rsa或其他任何东西。然后,在运行连接时,必须将pem文件的路径放在.ssh文件夹中:

ssh -i "C:\Users\[user]\.ssh\ubuntukp01.pem" ubuntu@ec[ipaddress].us-west-2.compute.amazonaws.com

对于我(使用Windows的Ubuntu子系统),错误消息更改为:

 Permissions 0555 for 'key.pem' are too open

在使用chmod 400之后。事实证明,使用root作为默认用户是原因。

使用cmd:

 ubuntu config --default-user your_username