首页 文章

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

提问于
浏览
122

我在我的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).

12 回答

  • 1

    我删除了 .pub file ,它有效 .

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

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

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

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

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

    IdentityFile .../.ssh/vm/vm_id_rsa
    
  • 82

    我建议你这样做:

    chmod 400 ~/.ssh/id_rsa
    

    对我来说工作很好 .

  • 285

    密钥应该由登录用户可读 .

    试试这个:

    cd ~/.ssh
    chmod 400 ~/.ssh/Key file
    chmod 400 ~/.ssh/vm_id_rsa.pub
    
  • 1
    chmod 400 path/to/filename
    

    这对我有用 . 当我做这个文件时,我能够连接到我的EC2实例

  • 8

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

    chmod 400~ / .ssh / id_rsa

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

    chmod 400 directory_path / id_rsa

    这对我有用 .

  • -7

    就我而言,它是一个.pem文件 . 事实证明这也是有益的 . 更改了文件的权限,并且工作正常 .

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

    感谢所有帮助过上述人士 .

  • 26

    至于我, id_rsa 的默认模式是 600 ,这意味着 readablewritable .

    在我将此文件推送到git repo并从另一台PC中提取之后,有时私钥文件的模式变为 -rw-r--r-- .

    当我在指定私钥文件后使用ssh提取repo时,它失败并提示警告与您相同 . 以下是我的脚本 .

    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
    
  • 30

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

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

  • 0

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

    chmod 0400 .ssh/config
    

    然后:

    chmod 0400 .ssh/<<KEYFILE_PATH>>
    
  • 9

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

  • 4

    赋予permision 400使密钥成为私有密钥,不被未知的人访问 . 它使密钥成为受保护密钥 .

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

相关问题