天天看點

在Windows中通過SSH工具連接配接虛拟機中的Linux

作者:樂其觀察

本文中使用的SSH工具是MobaXterm,Linux是深度作業系統(DeepinOS)。

在Windows中通過SSH工具連接配接虛拟機中的Linux

1、檢視系統是否安裝openssh

dpkg -l | grep openssh-server           
在Windows中通過SSH工具連接配接虛拟機中的Linux

此處已經顯示筆者系統裡安裝了,如果沒有任何輸出顯示就表示沒有安裝,通過指令

sudo apt install openssh-server           

2、切換到目錄/etc/ssh,使用vim編輯器打開sshd_config配置檔案,開啟監聽端口,監聽位址。

主要的幾句話需要放開,去掉#号。

sudo vim sshd_config           
#将檔案中,關于監聽端口、監聽位址前的 # 号去除
Port 22
AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::

#然後開啟允許遠端登入
PermitRootLogin yes

#最後,開啟使用使用者名密碼來作為連接配接驗證
PasswordAuthentication yes           

下面是已修改好的,可以比照參考,可以使用ssh工具連結的的sshd_config配置檔案。

Port 22
AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::

HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
AuthorizedKeysFile	.ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no           

按Esc鍵,退出編輯模式,輸入 :wq 回車,儲存剛才編輯好了的檔案。

3、開啟sshd 服務,輸入 指令

sudo service sshd start           

4、檢查 sshd 服務是否已經開啟,輸入指令

ps -e | grep sshd           
在Windows中通過SSH工具連接配接虛拟機中的Linux

如果有輸出顯示說明已經啟動。

5、檢視Linux的IP

ifconfig           
在Windows中通過SSH工具連接配接虛拟機中的Linux

6、在Windows中檢視是否能連通Linux

ping 192.168.189.130           
在Windows中通過SSH工具連接配接虛拟機中的Linux

7、用MobaXterm連接配接Linux

在Windows中通過SSH工具連接配接虛拟機中的Linux
在Windows中通過SSH工具連接配接虛拟機中的Linux
在Windows中通過SSH工具連接配接虛拟機中的Linux

出現以下畫面說明已經成功連接配接上虛拟機中的Linux,隻需輸入使用者名和密碼,也就是你的Linux的登入名和密碼。

在Windows中通過SSH工具連接配接虛拟機中的Linux

正确輸入使用者名和密碼後,登陸成功

在Windows中通過SSH工具連接配接虛拟機中的Linux

繼續閱讀