使用前的準(zhǔn)備
( 一 ) 更新系統(tǒng)
命令:
sudo apt-get update
sudo apt-get upgrade
( 二 ) 安裝SSH
注意子系統(tǒng)Ubuntu18.04中已安裝了OpenSSH
- 查看SSH安裝狀態(tài)
命令 : ps -e |grep ssh
#顯示以下類似狀態(tài),則已安裝
8677 ? 00:00:00 sshd
8784 ? 00:00:00 sshd
8787 ? 00:00:00 sshd
- 查看SSH版本號
命令: ssh -V
- 如果未安裝,則安裝
命令: sudo apt-get install openssh-server
( 三 ) 修改SSH配置文件
>命令: sudo vim /etc/ssh/sshd_config
#取消注釋, 修改默認(rèn)端口號22為23
Port 23
#取消注釋(可以不用)
ListenAddress 0.0.0.0
#取消注釋,允許root賬戶登錄
PermitRootLogin yes
#開啟密碼驗(yàn)證
PasswordAuthentication yes
#允許用戶登錄(可以不用)
UseLogin yes
UsePrivilegeSeparation no
#開啟密碼 登錄
PasswordAuthentication yes
# 選擇登錄賬戶(可以不用)
AllowUsers 登錄賬戶名
注意: 因?yàn)閣indows10自帶ssh服務(wù), 所以為了避免沖突, 需要修改默認(rèn)端口號22。
使用中
1. 開啟、重啟、停止服務(wù)
- 開啟
命令: sudo service ssh start
- 重啟
命令: sudo service ssh restart
- 停止
命令: sudo service ssh stop
2. 可能遇到的問題
- Server responded"Protocol error:packet too long:1349676920
原因:
修改SSH配置文件時未配置PermitRootLogin參數(shù)
解決辦法:
設(shè)置參數(shù):PermitRootLogin yes
- sshd error: could not load host key
查看key, 命令: ls -al /etc/ssh/ssh*key, 可能存在兩個狀態(tài),無key或者下面的狀態(tài):
root@DESKTOP-R9SRO56:~# ls -al /etc/ssh/ssh*key
#生成的key大小被截斷為0
-rw------- 1 root root 0 Sep 3 23:17 /etc/ssh/ssh_host_ecdsa_key
-rw------- 1 root root 0 Sep 3 23:17 /etc/ssh/ssh_host_ed25519_key
-rw------- 1 root root 0 Sep 3 23:17 /etc/ssh/ssh_host_rsa_key
原因:
SSH主機(jī)密鑰沒有成功生成
解決辦法:
sudo rm /etc/ssh/ssh*key //刪除現(xiàn)存有問題的key
dpkg-reconfigure openssh-serve //生成新的key
windows10連接子系統(tǒng)Ubunt
使用xshell等工具即可, ip地址為:127.0.0.1 端口為: 你自己定義的 賬戶:root 密碼:Ubuntu的root 的密碼
image.png
[C:\~]$
Connecting to 127.0.0.1:23...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.4.0-17134-Microsoft x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Tue Sep 4 14:21:01 DST 2018
System load: 0.52 Memory usage: 64% Processes: 13
Usage of /home: unknown Swap usage: 1% Users logged in: 0
=> There were exceptions while processing one or more plugins. See
/var/log/landscape/sysinfo.log for more information.
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
0 packages can be updated.
0 updates are security updates.
Last login: Tue Sep 4 14:07:54 2018 from 127.0.0.1
root@DESKTOP-R9SRO56:~#
如文中有錯誤或疑問, 敬請發(fā)郵件至Curllen@Foxmail.com
----歡迎轉(zhuǎn)載, 如轉(zhuǎn)載, 請說明轉(zhuǎn)載出處
