使用前的准备
( 一 ) 更新系统
命令:
sudo apt-get update
sudo apt-get upgrade
( 二 ) 安装SSH
注意子系统Ubuntu18.04中已安装了OpenSSH
- 查看SSH安装状态
命令 : ps -e |grep ssh
#显示以下类似状态,则已安装
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
#取消注释, 修改默认端口号22为23
Port 23
#取消注释(可以不用)
ListenAddress 0.0.0.0
#取消注释,允许root账户登录
PermitRootLogin yes
#开启密码验证
PasswordAuthentication yes
#允许用户登录(可以不用)
UseLogin yes
UsePrivilegeSeparation no
#开启密码 登录
PasswordAuthentication yes
# 选择登录账户(可以不用)
AllowUsers 登录账户名
注意: 因为windows10自带ssh服务, 所以为了避免冲突, 需要修改默认端口号22。
使用中
1. 开启、重启、停止服务
- 开启
命令: sudo service ssh start
- 重启
命令: sudo service ssh restart
- 停止
命令: sudo service ssh stop
2. 可能遇到的问题
- Server responded"Protocol error:packet too long:1349676920
原因:
修改SSH配置文件时未配置PermitRootLogin参数
解决办法:
设置参数:PermitRootLogin yes
- sshd error: could not load host key
查看key, 命令: ls -al /etc/ssh/ssh*key, 可能存在两个状态,无key或者下面的状态:
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主机密钥没有成功生成
解决办法:
sudo rm /etc/ssh/ssh*key //删除现存有问题的key
dpkg-reconfigure openssh-serve //生成新的key
windows10连接子系统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:~#
如文中有错误或疑问, 敬请发邮件至Curllen@Foxmail.com
----欢迎转载, 如转载, 请说明转载出处
网友评论