如何为Vagrant VM启用密码ssh身份验证?

cze*_*rny 11 passwords ssh vagrant

我想为可能Vagrant VM启用密码ssh身份验证(并启用基于密钥的身份验证).怎么设置?

Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "fedora/26-cloud-base"
  config.vm.box_version = "20170705"

  config.ssh.username = 'vagrant'
  config.ssh.password = 'a'
  config.ssh.keys_only = false
end
Run Code Online (Sandbox Code Playgroud)
$ sudo vagrant ssh-config 
Host default
  HostName 192.168.121.166
  User vagrant
  Port 22
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/jakub/src/kubernetes-vms/kubernetes/.vagrant/machines/default/libvirt/private_key
  LogLevel FATAL
Run Code Online (Sandbox Code Playgroud)

a此设置不接受密码.

我想可能是PasswordAuthentication no在输出中vagrant ssh-config.如何打开该选项?

kya*_*kya 11

在 centos 7 上,仅使用以下是不够的。通过这种方式,我猜它只是su vagrant通过密码变成了。我找不到任何为什么下面在官方网站上不起作用的原因。

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"

  config.ssh.username = 'vagrant'
  config.ssh.password = 'vagrant'
  config.ssh.insert_key = false
end
Run Code Online (Sandbox Code Playgroud)

您应该手动修改 sshd_config。

  config.vm.provision "shell", inline: <<-SHELL
     sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config    
     systemctl restart sshd.service
  SHELL
Run Code Online (Sandbox Code Playgroud)


Fre*_*man 8

对我来说,以下工作.您需要像往常一样ssh到vm然后编辑/etc/ssh/sshd_config.在那里,您需要设置PasswordAuthenticationyes代替no.这将允许密码验证.

  • 有没有一种适当的方法来在“ Vagrantfile”中编写脚本,而不是手动配置ssh?顺便说一句:您还需要在更改后重新启动sshd(即systemctl restart sshd) (2认同)

cze*_*rny 5

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "fedora/26-cloud-base"
  config.vm.box_version = "20170705"

  config.vm.provision 'shell', inline: 'echo "vagrant:a" | chpasswd'
end
Run Code Online (Sandbox Code Playgroud)

config.vm.provision 'shell', inline: 'echo "vagrant:a" | chpasswd'调用更改vagrant用户密码的 shell 配置(前提是该框带有名为 的预定义用户vagrant)。

那么一个人不仅可以通过vagrant ssh而且还可以连接

ssh vagrant@<vm-ip>
Run Code Online (Sandbox Code Playgroud)


Fré*_*nri 4

如果您想对虚拟机强制进行密码身份验证,则需要在 Vagrantfile 中设置以下内容

  config.ssh.username = 'vagrant'
  config.ssh.password = 'vagrant'
  config.ssh.insert_key = false
Run Code Online (Sandbox Code Playgroud)

您需要确保vagrant虚拟机中的用户有相应的密码。我不确定您使用的盒子,因此您需要自行验证。它适用于以下盒子:ubuntu/trusty64

  • 您混淆了身份验证和密码设置。您需要在虚拟机中正确设置用户(使用密码),并且“config.ssh.password”可以让 vagrant 知道需要哪个密码来验证用户身份。它不是为用户设置新密码(您首先需要登录虚拟机才能进行此更改) (2认同)