docker(十):xshell连接vagrant创建的虚拟机centos7

一、实现功能

使用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端口,也是可以访问的。大功告成~

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值