Vagrant(二)Xshell登录Vagrant方式

Xshell登录Vagrant方式

我上一篇文章 介绍了vagrant 如何创建虚拟机集群,在上篇文章的基础上,用xshell 登录 虚拟机发现 默认是无法使用账号密码登录root账号,只能使用vagrant账号,密码vagrant,

vagrant账号登录

在虚拟机 vagrantfile 的目录位置 打开控制台,输入vagrant ssh-config

$ vagrant ssh-config

Host k8s-m1
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile D:/vagrant-file/file1/.vagrant/machines/k8s-m1/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL

Host k8s-n2
HostName 127.0.0.1
User vagrant
Port 2200
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile D:/vagrant-file/file1/.vagrant/machines/k8s-n2/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

查看 hostname ,port,IdentityFile 这三个位置

xshell登录

有可能不能选择密码登录,默认是用密钥登录,浏览,文件,找到 刚刚的IdentityFile ,再输入密码vagrant 就可以使用vagrant 用户 ssh登录

root账号登录

vagrant登陆后,切换到root账号

$ sudo -i

 
 
  • 1

设置root的密码
在这里插入图片描述
修改 /etc/ssh/sshd_config 文件,(注意,vagrant用户下这个文件是只读的,可能什么也看不见)
修改 ssd_config 里 PermitRootLogin属性 改为yes ,并把前面的# 去掉
在这里插入图片描述

PasswordAuthentication 改为yes 并且去掉 #
在这里插入图片描述

保存退出,重启sshd服务

$ systemctl restart sshd

 
 
  • 1

再通过xshell连接的时候,就可以用账号密码,root来登录了

问题:虽然xshell里都是用127.0.0.1:2222或者2200 这种登录的,但是也可以使用自己设置的ip 例如192.16.25.11:22 去登录,这里用自己设置的ip时端口则是22。
设置完成以后就和自己开的虚拟机没什么两样了。

        </div>
					<link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-2b43bc2447.css" rel="stylesheet">
            </div>
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值