vagrant root login virtual machine

This problem could have been that is a particularly simple question, get yesterday when tossing half the night. So I plan to record the process, the main variety of information online has also been misled.

1

I look at this vagrant configuration information

Vagrant.configure("2") do |config|
  config.vm.box = "base"
  config.vm.box_check_update = false
  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "private_network", ip: "192.168.0.1"
  config.vm.synced_folder "/data/www", "/data/www"
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end

I found no login information, and then checked the online information that is the default login user name is the vagrant, the same password. Like below.

config.ssh.username = "vagrant"
config.ssh.password = "vagrant"

Configuration on the above information and vagrant ssh login, login normally found no problems. Change the root password.

sudo -s
passwd

After it modified according to online information

vim /etc/ssh/sshd_config
PermitRootLogin prohibit-password
改为
PermitRootLogin yes
重启ssh服务
service sshd restart

Withdraw, modify vagrant login information

config.ssh.username = "root"
config.ssh.password = "密码"
然后
vagrant ssh
提示
[email protected]: Permission denied (publickey).

Login not allowed. I have not understood. Later, under carefully read the
/ etc / ssh / sshd_config
found a password on the configuration of
PasswordAuthentication no
means should be password authorization, to try to open the configuration

PasswordAuthentication yes
记着重启服务
service sshd restart

Then change the configuration username
config.ssh.username = "root"
config.ssh.password = "password"
This is looking at a prompt for the root password, after entering the finish, you can log in directly to the value.

2

Wait, I'm not configure a password yet? Why prompted me for a password
config.ssh.password = "password"
into vagrant user name, password configuration try commented, still log in normally. Replaced in the root user name, password commented configuration, prompted for a password, password configuration instructions no practical significance, with no need to manually configure the password.

However, vagrant why users can directly log on without a password, the default is the secret key may vagrant login. I look at the keys to log vagrant configuration.

vim ~/.ssh/authorized_keys
果然有秘钥配饰
JbDoShF6plkIvZfV1ol3OMGYRtG8V/fYOCgfv9VBHmBVda+yIuybtD vagrant

Confirms our guess, vagrant default secret key login, password configuration does not make any sense.
Then how do we put our keys changed to the root user to log it?
Here we look at the configuration steps
first log in using root password lost

vim /etc/ssh/sshd_config
打开两个关于秘钥的配置
RSAAuthentication yes
PubkeyAuthentication yes

配置公钥
vim ~/.ssh/authorized_keys
将自己的公钥添加到这里。
重启服务
service sshd restart
exit
退出虚拟机

Modify vagrant configuration data, notes password, plus private address,

config.ssh.username = "root"
#config.ssh.password = "vagrant"
config.ssh.private_key_path = "/Users/XXX/.ssh/id_rsa"

Not surprisingly, you can avoid dense like vagrant user logged in.
Sometimes prompted to enter private key password, indicating that no private address found, the operation of the private key can be added next to do.

sudo ssh-add -K ~/.ssh/id_rsa

Is free secret keys can be registered? ? ?

Guess you like

Origin www.cnblogs.com/golangcode/p/10958361.html
Recommended