Xshell登陸Vagrant方式

Xshell登陸Vagrant方式

我上一篇文章 介紹了vagrant 如何建立虛擬機集羣,在上篇文章的基礎上,用xshell 登陸 虛擬機發現 默認是沒法使用帳號密碼登陸root帳號,只能使用vagrant帳號,密碼vagrant,
vagrant帳號登陸

在虛擬機 vagrantfile 的目錄位置 打開控制檯,輸入vagrant ssh-config

php

$ 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帳號git

$ sudo -i

設置root的密碼

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

PasswordAuthentication 改成yes 而且去掉 #

保存退出,重啓sshd服務

github

$ systemctl restart sshd

再經過xshell鏈接的時候,就能夠用帳號密碼,root來登陸了

問題:雖然xshell裏都是用127.0.0.1:2222或者2200 這種登陸的,可是也能夠使用本身設置的ip 例如192.16.25.11:22 去登陸,這裏用本身設置的ip時端口則是22
設置完成之後就和本身開的虛擬機沒什麼兩樣了。shell

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

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



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

.net

相關文章
相關標籤/搜索