安装Oracle Database 19c 的 VagrantBox ,非常顺利,耗时如下:
real 30m36.783s
user 0m0.000s
sys 0m0.047s
前面一切顺利,但是vagrant ssh和vagrant putty均不能登录虚机。我的环境是Windows 11,Vagrant 2.4和VirtualBox 7.0。
这个错误肯定是和ssh相关的,以下命令显示了vagrant中ssh的配置。其中IdentityFile就是私钥文件:
$ vagrant ssh-config
Host oracle-19c-vagrant
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile C:/Users/****/Desktop/WORKSPACE/vagrant-projects/OracleDatabase/19.3.0/.vagrant/machines/oracle-19c-vagrant/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
PubkeyAcceptedKeyTypes +ssh-rsa
HostKeyAlgorithms +ssh-rsa
利用上面的信息,就可以用ssh直接登录来测试了。
vagrant ssh不能登录虚机
$ vagrant ssh
vagrant@127.0.0.1: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
没有权限这个报错真是太抽象了,误导了我很长时间。
如果用ssh直接登录,错误类似,但会多一个Load key的信息:
$ ssh -l vagrant -p 2222 -i "C:/Users/XiaoYu/Desktop/WORKSPACE/vagrant-projects/OracleDatabase/19.3.0/.vagrant/machines/oracle-19c-vagrant/virtualbox/private_key" 127.0.0.1
The authenticity of host '[127.0.0.1]:2222 ([127.0.0.1]:2222)' can't be established.
ED25519 key fingerprint is SHA256:WnMw/1XuV9GuqSxZfkP239KEN4bVrONP61AtVVzqvk0.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[127.0.0.1]:2222' (ED25519) to the list of known hosts.
Load key "C:/Users/XiaoYu/Desktop/WORKSPACE/vagrant-projects/OracleDatabase/19.3.0/.vagrant/machines/oracle-19c-vagrant/virtualbox/private_key": error in libcrypto
vagrant@127.0.0.1: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
最终是这个帖子提供了解决方法,原因是私钥文件的格式不对。
I would double check that your private key secret has a newline character at the end of the file, because for some reason libcrypto requires it to be a “valid format”
因为我是在gitbash下运行vagrant ssh命令的,gitbash需要Linux格式的密钥文件,而此时的秘钥文件为DOS格式。因此,用gitbash下提供dos2unix命令转换就好:
$ dos2unix.exe C:/Users/XiaoYu/Desktop/WORKSPACE/vagrant-projects/OracleDatabase/19.3.0/.vagrant/machines/oracle-19c-vagrant/virtualbox/private_key
dos2unix: converting file C:/Users/XiaoYu/Desktop/WORKSPACE/vagrant-projects/OracleDatabase/19.3.0/.vagrant/machines/oracle-19c-vagrant/virtualbox/private_key to Unix format...
如果你用vi查看文件,你会发现底部有dos的显示,转换后就变为unix了:
以下是成功的登录:
$ vagrant ssh
Last login: Wed Jan 10 21:01:16 2024 from 10.0.2.2
Welcome to Oracle Linux Server release 7.9 (GNU/Linux 5.4.17-2136.325.5.el7uek.x86_64)
The Oracle Linux End-User License Agreement can be viewed here:
* /usr/share/eula/eula.en_US
For additional packages, updates, documentation and community help, see:
* https://yum.oracle.com/
[vagrant@oracle-19c-vagrant ~]$
vagrant putty 不能登录虚机
错误如下:
$ vagrant putty
C:/Users/XiaoYu/.vagrant.d/gems/3.1.3/gems/vagrant-multi-putty-1.6.0/lib/vagrant-multi-putty/command.rb:114:in `read': Could not parse PKey: unsupported (OpenSSL::PKey::PKeyError)
from C:/Users/XiaoYu/.vagrant.d/gems/3.1.3/gems/vagrant-multi-putty-1.6.0/lib/vagrant-multi-putty/command.rb:114:in `block in get_putty_key_file'
from <internal:kernel>:90:in `tap'
from C:/Users/XiaoYu/.vagrant.d/gems/3.1.3/gems/vagrant-multi-putty-1.6.0/lib/vagrant-multi-putty/command.rb:112:in `get_putty_key_file'
from C:/Users/XiaoYu/.vagrant.d/gems/3.1.3/gems/vagrant-multi-putty-1.6.0/lib/vagrant-multi-putty/command.rb:94:in `putty_connect'
from C:/Users/XiaoYu/.vagrant.d/gems/3.1.3/gems/vagrant-multi-putty-1.6.0/lib/vagrant-multi-putty/command.rb:53:in `block in execute'
from C:/Program Files/Vagrant/embedded/gems/gems/vagrant-2.4.0/lib/vagrant/plugin/v2/command.rb:249:in `block in with_target_vms'
from C:/Program Files/Vagrant/embedded/gems/gems/vagrant-2.4.0/lib/vagrant/plugin/v2/command.rb:238:in `each'
from C:/Program Files/Vagrant/embedded/gems/gems/vagrant-2.4.0/lib/vagrant/plugin/v2/command.rb:238:in `with_target_vms'
from C:/Users/XiaoYu/.vagrant.d/gems/3.1.3/gems/vagrant-multi-putty-1.6.0/lib/vagrant-multi-putty/command.rb:51:in `execute'
from C:/Program Files/Vagrant/embedded/gems/gems/vagrant-2.4.0/lib/vagrant/cli.rb:67:in `execute'
from C:/Program Files/Vagrant/embedded/gems/gems/vagrant-2.4.0/lib/vagrant/environment.rb:319:in `cli'
from C:/Program Files/Vagrant/embedded/gems/gems/vagrant-2.4.0/bin/vagrant:248:in `<main>'
如果putty直接登录:
putty -l vagrant -P 2222 -i "C:/Users/XiaoYu/Desktop/WORKSPACE/vagrant-projects/OracleDatabase/19.3.0/.vagrant/machines/oracle-19c-vagrant/virtualbox/private_key" 127.0.0.1
报错如下:
这个错误的原因在于,putty需要的密钥是PPK格式,而在密钥目录下,这个PPK文件不存在(原因尚不知道),但openssh格式的密钥文件private_key是存在的。
$ cd .vagrant/machines/oracle-19c-vagrant/virtualbox/
$ ls *key*
private_key
$ cat private_key
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1r...
bucpF2j40j3P6HpKqZaLac+gSYPHu42dSjSRObH7jgFltC8FwlslPuVAvY4W
AAAAB3ZhZ3JhbnQBAgMEBQY=
-----END OPENSSH PRIVATE KEY-----
所以,只需要通过puttygen将private_key导入,转换后另存为private_key.ppk到其目录下即可。
$ ls *key*
private_key private_key.ppk