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

查看 hostname ,port,IdentityFile 這三個位置

有可能不能選擇密碼登錄,默認是用密鑰登錄,瀏覽,文件,找到 剛剛的IdentityFile ,再輸入密碼vagrant 就可以使用vagrant 用戶 ssh登錄
root賬號登錄

vagrant登陸后,切換到root賬號

$ sudo -i

設置root的密碼

修改 /etc/ssh/sshd_config 文件,(注意,vagrant用戶下這個文件是只讀的,可能什么也看不見)
修改 ssd_config 里 PermitRootLogin屬性 改為yes ,並把前面的# 去掉

PasswordAuthentication 改為yes 並且去掉 #

保存退出,重啟sshd服務

$ systemctl restart sshd

再通過xshell連接的時候,就可以用賬號密碼,root來登錄了

問題:雖然xshell里都是用127.0.0.1:2222或者2200 這種登錄的,但是也可以使用自己設置的ip 例如192.16.25.11:22 去登錄,這里用自己設置的ip時端口則是22
設置完成以后就和自己開的虛擬機沒什么兩樣了。

本地:使用私鑰方式(找到E:\wwwroot\.vagrant\machines\default\virtualbox\private_keywe文件)  ip:127.0.0.1  端口:2222

本地2:使用賬號密碼:root/root#1234    ip:192.168.33.10    端口:22



原文:https://blog.csdn.net/github_38097011/article/details/83688607


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM