代码之家  ›  专栏  ›  技术社区  ›  nielsv

无法连接到宅MySQL数据库-权限被拒绝(公钥、密码)

  •  0
  • nielsv  · 技术社区  · 4 年前

    我正在与合作 Homestead 和流浪在我的地方设置。我的Homestead.yaml文件如下所示:

    ---
    ip: "192.168.56.56"
    memory: 4096
    cpus: 2
    provider: virtualbox
    
    authorize: ~/.ssh/id_rsa.pub
    
    keys:
        - ~/.ssh/id_rsa
    
    folders:
        - map: ~/projects
          to: /home/vagrant/projects
          type: "nfs"
    
    sites:
        - map: volley.admin
          to: /home/vagrant/projects/volleyadmin/public
          type: laravel
          php: "7.1"
    
    databases:
        - volleyadmin
    
    features:
        - mysql: true
        - mariadb: false
        - postgresql: false
        - ohmyzsh: false
        - webdriver: false
    
    services:
        - enabled:
              - "mysql"
    #    - disabled:
    #        - "postgresql@11-main"
    
    #ports:
    #    - send: 33060 # MySQL/MariaDB
    #      to: 3306
    #    - send: 4040
    #      to: 4040
    #    - send: 54320 # PostgreSQL
    #      to: 5432
    #    - send: 8025 # Mailhog
    #      to: 8025
    #    - send: 9600
    #      to: 9600
    #    - send: 27017
    #      to: 27017
    

    我做了流浪和流浪ssh,一切看起来都很正常。问题是我无法用连接到我的数据库 Sequel Ace

    我的配置如下所示:

    enter image description here

    MySQL密码:secret SSH密码:secret

    当我尝试连接时,我得到以下响应:

    Used command:  /usr/bin/ssh -v -N -S none -o ControlMaster=no -o ExitOnForwardFailure=yes -o ConnectTimeout=10 -o NumberOfPasswordPrompts=3 -o UserKnownHostsFile="/Users/nielsvroman/Library/Containers/com.sequel-ace.sequel-ace/Data/.keys/ssh_known_hosts_strict" -F /Applications/Sequel Ace.app/Contents/Resources/ssh_config -o TCPKeepAlive=no -o ServerAliveInterval=60 -o ServerAliveCountMax=1 [email protected] -L 50489:127.0.0.1:3306
    
    OpenSSH_8.6p1, LibreSSL 3.3.5
    debug1: Reading configuration data /Applications/Sequel Ace.app/Contents/Resources/ssh_config
    debug1: /Applications/Sequel Ace.app/Contents/Resources/ssh_config line 1: Applying options for *
    debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
    debug1: Connecting to 192.168.56.56 [192.168.56.56] port 22.
    debug1: fd 3 clearing O_NONBLOCK
    debug1: Connection established.
    debug1: identity file /Users/nielsvroman/.keys/id_rsa type -1
    debug1: identity file /Users/nielsvroman/.keys/id_rsa-cert type -1
    debug1: Local version string SSH-2.0-OpenSSH_8.6
    debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.4
    debug1: compat_banner: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.4 pat OpenSSH* compat 0x04000000
    debug1: Authenticating to 192.168.56.56:22 as 'vagrant'
    debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
    debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug1: kex: algorithm: curve25519-sha256
    debug1: kex: host key algorithm: ssh-ed25519
    debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
    debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
    debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
    debug1: SSH2_MSG_KEX_ECDH_REPLY received
    debug1: Server host key: ssh-ed25519 SHA256:r6W0RoVMAo3PNslyC8hel/ZlozmmV4vIpdulB7LmOEc
    debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
    debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
    debug1: Host '192.168.56.56' is known and matches the ED25519 host key.
    debug1: Found key in /Users/nielsvroman/Library/Containers/com.sequel-ace.sequel-ace/Data/.keys/ssh_known_hosts_strict:1
    debug1: rekey out after 134217728 blocks
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug1: SSH2_MSG_NEWKEYS received
    debug1: rekey in after 134217728 blocks
    debug1: pubkey_prepare: ssh_get_authentication_socket: Operation not permitted
    debug1: Will attempt key: /Users/nielsvroman/.keys/id_rsa  explicit
    debug1: SSH2_MSG_EXT_INFO received
    debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected]>
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug1: Authentications that can continue: publickey,password
    debug1: Next authentication method: publickey
    debug1: Trying private key: /Users/nielsvroman/.keys/id_rsa
    no such identity: /Users/nielsvroman/.keys/id_rsa: No such file or directory
    debug1: Next authentication method: password
    debug1: read_passphrase: can't open /dev/tty: Device not configured
    debug1: Authentications that can continue: publickey,password
    Permission denied, please try again.
    debug1: read_passphrase: can't open /dev/tty: Device not configured
    debug1: Authentications that can continue: publickey,password
    Permission denied, please try again.
    debug1: read_passphrase: can't open /dev/tty: Device not configured
    debug1: Authentications that can continue: publickey,password
    debug1: No more authentication methods to try.
    [email protected]: Permission denied (publickey,password).
    The SSH Tunnel could not authenticate with the remote host. Please check your password and ensure you still have access.
    
    0 回复  |  直到 4 年前
        1
  •  2
  •   Kenster marc_s    4 年前

    你的 Homestead.yaml file表示ssh密钥文件位于其典型位置: ~/.ssh/id_rsa 。但是,调试输出显示ssh正在另一个位置查找密钥:

    debug1: Next authentication method: publickey
    debug1: Trying private key: /Users/nielsvroman/.keys/id_rsa
    no such identity: /Users/nielsvroman/.keys/id_rsa: No such file or directory
                                         ^^^^^ 
    

    它正在向内看 ~/.keys 而不是 ~/.ssh 。密钥不在那个位置,所以ssh找不到它,也不会将它提供给远程系统。

    根据调试输出中的“用户命令”行,ssh是使用非标准配置文件运行的, /Applications/Sequel Ace.app/Contents/Resources/ssh_config 。这个文件可能包含一些配置选项,这些选项导致ssh在 .keys 关键文件的目录,而不是 .ssh 目录

    简单的解决方案是复制您的关键文件( id_rsa _id_rsa.pub )来自您的 .ssh 目录到此 .键 目录关键文件并不很大,将它们放在多个地方也没有真正的问题。

    或者,您可以编辑这个特殊的ssh配置文件,使其在通常的位置查找关键文件。有必要确定导致ssh在其他目录中查找的配置选项,并更改或删除它们。看起来这个特殊的配置文件是你安装的某个软件的一部分?更改配置文件可能会影响软件的工作方式,或者每次更新软件时都会为您重新编辑文件带来额外的工作。

        2
  •  0
  •   ZyDucksLover    3 年前

    我个人在2022年末也遇到了同样的问题。修复方法是,我必须使用与Homestead.yaml文件中相同的IP作为主机地址(即 192.168.56.56 默认情况下)。

    推荐文章