一、实现功能
使用vagrant创建centos7虚拟机,然后,使用powershell的“vagrant ssh 主机名”连接是可以连接到主机的。但是,使用xshell却无法直接连接。所以,在此记录一下使用xshell连接虚拟机方法,从而使使用更加方便。
二、步骤
1.进入vagrantfile所在目录,执行vagrant ssh-config
#vagrant ssh-config
查看
Host docker-node1
HostName 127.0.0.1
User vagrant
Port 2200
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile F:/BGLearn/10docker/docker-k8s-devops-master-9287a2ca56433ca076078b564de9488df81b40be/chapter4/.vagrant/machines/docker-node1/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
Host docker-node2
HostName 127.0.0.1
User vagrant
Port 2201
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile F:/BGLearn/10docker/docker-k8s-devops-master-9287a2ca56433ca076078b564de9488df81b40be/chapter4/.vagrant/machines/docker-node2/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
查看hostname ,port,IdentityFile三个参数
2.使用xshell
(1)IP和端口号采用上面的1和2
(2)用户名和密码:vagrant/vagrant
密码选择上一步骤中的3的private_key,然后输入vagrant
(3)登录成功
Connecting to 127.0.0.1:2200...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Tue Jun 25 13:32:45 2019 from 10.0.2.2
[vagrant@docker-node1 ~]$
3.配置xshell远程root用户登录
(1)在上一步vagrant登陆后
sudo -i
(2)设置root的密码
vi /etc/ssh/sshd_config
(3)修改属性,并且取消前面的#
PasswordAuthentication yes
PermitRootLogin yes
(4)重启ssh服务,即可xshell连接
systemctl restart sshd
(5)使用root/vagrant即可连接,ip和端口号为127.0.0.1:2222
4.使用ip连接
因为创建虚拟机时,指定ip为192.168.205.10和192.168.205.11,所以,此时可以通过xshell连接192.168.205.10和22端口,也是可以访问的。大功告成~