连接 MySQL workbench 到 vagrant 时出现 SSH 问题

SSH issue when connection MySQL workbench to vagrant

我正在尝试使用 MySQL workbench 连接到我的 vagrant MySQL 服务器。它显示了一些错误,如图所示。

下面粘贴了 workbench 错误日志。

17:34:50 [INF][     SSH tunnel]: Existing SSH tunnel not found, opening new one
17:34:50 [INF][     SSH tunnel]: Opening SSH tunnel to 127.0.0.1:2222
17:34:50 [ERR][   sshtunnel.py]: Traceback (most recent call last):
  File "/usr/share/mysql-workbench/sshtunnel.py", line 231, in _connect_ssh
    look_for_keys=has_key, allow_agent=has_key)
  File "/usr/lib/python2.7/dist-packages/paramiko/client.py", line 337, in connect
    self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
  File "/usr/lib/python2.7/dist-packages/paramiko/client.py", line 528, in _auth
    raise saved_exception
AuthenticationException: Authentication failed.
17:34:50 [ERR][     SSH tunnel]: Authentication error opening SSH tunnel: Authentication error. Please check that your username and password are correct and try again.

vagrant up 命令输出粘贴在下方

==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 6216 (adapter 1)
    default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...

命令 vagrant ssh 在终端中运行良好。我在这里做错了什么?

关于您在评论中提到的错误: 使用 ssh 时,您不要像这样指定端口

ssh 127.0.0.1:2222

您必须使用选项 -p

ssh 127.0.0.1 -p 2222

经过一番谷歌搜索后,我通过将我的 ssh public 密钥添加到 vagrant authorized_keys 文件来让它工作。下面的步骤。

  1. generate ssh keys 适合您的机器
  2. /home/{username}/.ssh/id_rsa.pub 文件中复制您的 public 密钥
  3. 在终端
  4. 中打开vagrant ssh
  5. 使用一些编辑器编辑/home/vagrant/.ssh/authorized_keys(例如:nano /home/vagrant/.ssh/authorized_keys
  6. 将您的 public 密钥粘贴到该文件的末尾并保存

完成!

如果你 运行 vagrant ssh-config 它会显示它正在使用哪个键。它通常不使用 .vagrant.d/insecure_private_key 而是项目目录中的一个键,例如 .vagrant/machines/default/virtualbox/private_key.

如果您在 MySQL 连接面板中指定该密钥,您应该能够登录而无需向虚拟机添加另一个密钥。