SSH密钥:“'id_rsa.pub'的权限0644太开放了。”在mac上

时间:2015-04-29 03:40:47

标签: ssh permissions key

我在我的mac上生成了一个ssh密钥对,并将公钥添加到我的ubuntu服务器上(事实上,它是我的mac上的虚拟机),但是当我尝试登录ubuntu服务器时,它说:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/Users/tudouya/.ssh/vm/vm_id_rsa.pub' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /Users/tudouya/.ssh/vm/vm_id_rsa.pub
Permission denied (publickey,password).

我已经尝试了很多方法来解决这个问题,更改密钥文件模式,更改文件夹模式,就像stackoverflow上的一些答案一样,但它不起作用。
密钥文件权限:

vm dir:
drwxr-xr-x   4 tudouya  staff    136  4 29 10:37 vm

key file:
-rw-------  1 tudouya  staff  1679  4 29 10:30 vm_id_rsa
-rw-r--r--  1 tudouya  staff   391  4 29 10:30 vm_id_rsa.pub

请给我一些想法...... =========================================

我将主机信息写入ssh_config:

Host ubuntuvm
    Hostname 10.211.55.17
    PreferredAuthentications publickey
    IdentityFile /Users/tudouya/.ssh/vm/vm_id_rsa.pub

我运行命令“ssh -v ubuntuvm”,它显示:

ssh -v ubuntuvm
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 103: Applying options for *
debug1: /etc/ssh_config line 175: Applying options for ubuntuvm
debug1: Connecting to 10.211.55.17 [10.211.55.17] port 22.
debug1: Connection established.
debug1: identity file /Users/tudouya/.ssh/vm/vm_id_rsa.pub type 1
debug1: identity file /Users/tudouya/.ssh/vm/vm_id_rsa.pub-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-8
debug1: match: OpenSSH_6.6.1p1 Ubuntu-8 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 55:6d:4f:0f:23:51:ac:8e:70:01:ec:0e:62:9e:1c:10
debug1: Host '10.211.55.17' is known and matches the RSA host key.
debug1: Found key in /Users/tudouya/.ssh/known_hosts:54
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/tudouya/.ssh/vm/vm_id_rsa.pub
debug1: Server accepts key: pkalg ssh-rsa blen 279
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/Users/tudouya/.ssh/vm/vm_id_rsa.pub' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /Users/tudouya/.ssh/vm/vm_id_rsa.pub
debug1: No more authentication methods to try.
Permission denied (publickey,password).

20 个答案:

答案 0 :(得分:363)

我建议你这样做:

chmod 400 ~/.ssh/id_rsa

对我来说工作很好。

答案 1 :(得分:99)

debug1: identity file /Users/tudouya/.ssh/vm/vm_id_rsa.pub type 1

您似乎正在尝试使用错误的密钥文件。扩展名为“.pub”的文件是 public 密钥文件。没有“.pub”扩展名的相应文件是私有密钥文件。当您运行ssh客户端以连接到远程服务器时,您必须将私钥文件提供给ssh客户端。

您的.ssh/config文件(或/etc/ssh_config)中可能有一行,如下所示:

IdentityFile .../.ssh/vm/vm_id_rsa.pub

您需要从文件名中删除“.pub”扩展名:

IdentityFile .../.ssh/vm/vm_id_rsa

答案 2 :(得分:35)

登录用户应该可以读取密钥。

试试这个:

cd ~/.ssh
chmod 400 ~/.ssh/Key file
chmod 400 ~/.ssh/vm_id_rsa.pub

答案 3 :(得分:33)

chmod 400 path/to/filename

这项工作对我而言。当我执行此文件时,我能够连接到我的EC2实例

答案 4 :(得分:19)

就我而言,这是一个.pem文件。事实证明也是如此。更改了文件的权限,它起作用了。

chmod 400 ~/.ssh/dev-shared.pem

感谢所有提供帮助的人。

答案 5 :(得分:11)

SSH密钥是专用的,因此644权限太开放了。

设置权限的二进制引用

 r(read) = 4
 w(write) = 2
 x(execute) = 1

因此,通过添加这些数字并将总和的数字传递给chmod命令,我们可以设置文件/目录的许可权。 第一位数字设置所有者的权限,第二位数字设置组的权限,第三位数字设置对系统上没有该文件权限的所有其他用户的权限。

A permission of 644 means 
(4+2) = read/write permission for the owner
(4) = read permission for the group 
(4) = read permission for all other users 
 

通过使用将文件的权限更改为400

chmod 400 <filename>

解决了问题。因为它使密钥对所有者具有只读权限。

参考:https://www.linux.com/training-tutorials/understanding-linux-file-permissions/

答案 6 :(得分:11)

如果密钥位于〜/ .ssh目录中,请使用

chmod 400~ / .ssh / id_rsa

如果密钥位于不同的目录中,请使用

chmod 400 directory_path / id_rsa

这对我有用。

答案 7 :(得分:7)

对于我来说,id_rsa的默认模式是600,表示readablewritable

将这个文件推送到git repo并将其从另一台PC中拉出后,有时私钥文件的模式变为-rw-r--r--

当我在指定私钥文件后用ssh拉回购时,它失败了,并提示警告与您相同。以下是我的脚本。

ssh-agent bash -c "ssh-add $PATH_OF_RSA/id_rsa; \
git pull git@gitee.com:someone/somerepo.git "

我仅通过将模式更改为600即可解决此问题。

chmod 600 $PATH_TO_RSA/id_rsa

答案 8 :(得分:4)

赋予权限400将密钥设为私有,并且未知者无法访问。它使密钥成为受保护的密钥。

chmod 400 /Users/tudouya/.ssh/vm/vm_id_rsa.pub

答案 9 :(得分:3)

很多类似的答案,但没有解释...

由于私钥文件权限太开放而引发错误。这是安全隐患。

将私钥文件的权限更改为最小限度(仅供所有者读取)

  1. 更改所有者var array = [{"title":"Ender's Game","genre":"Science Fiction","year":2008},{"title":"Harry Potter and the Goblet of Fire","genre":"fantasy","year":2002},{"title":"Pride and Predjudice","genre":"romance","year":1980}] function getLongest(array){ return array.map((obj) => obj.genre.length).sort((a, b)=>{ return (b - a); //sorting in descending order })[0]; //first element will hold the longest genre } console.log(getLongest(array));
  2. 设置最低权限(只读给文件所有者)chown <unix-name> <private-key-file>

答案 10 :(得分:3)

在运行以下命令后,它对我有用

sudo chmod 600 /path/to/my/key.pem

答案 11 :(得分:3)

chmod 600 id_rsa

从密钥存储在vm ex中的路径上运行上述命令:cd /home/opc/.ssh

答案 12 :(得分:2)

如果您使用.ssh / config文件,请尝试

chmod 0400 .ssh/config

然后:

chmod 0400 .ssh/<<KEYFILE_PATH>>

答案 13 :(得分:2)

那些建议chmod 400 id_rsa.pub的人根本听起来不对。 op很可能使用pub键而不是私钥来ssh。

所以它可能像ssh -i /Users/tudouya/.ssh/vm/vm_id_rsa (the private key) user@host一样简单来修复它。

---更新---

查看本文https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2了解如何设置ssh密钥

答案 14 :(得分:1)

chmod 400 /etc/ssh/*适合我。

答案 15 :(得分:1)

你必须运行下面的命令

chmod 400 /path/to/my/key.pem

答案 16 :(得分:0)

在我的情况下,如果发现该文件实际上并不是我需要的文件,因为显然我用来创建 ssh 密钥的命令 ssh-keygen -t rsa

在我正在使用的文件目录中为我创建了密钥,并使用了我使用的名称。

因此检查您正在工作的目录中的隐藏文件,您可能只会看到 ssh 和 ssh.pub

答案 17 :(得分:0)

这应该可以解决问题:

chmod 600 id_rsa

答案 18 :(得分:0)

只要在下面跑到你的pem

sudo chmod 600 /path/to/my/key.pem 

答案 19 :(得分:-8)

我删除了.pub file,但它确实有效。