WSL中已经内置了ssh服务,但是看到有帖子说自带的ssh有问题,因此卸载掉重新安装
ss ssdpapi.dll ssh-agent ssh-import-id-gh ssh-keyscan.exe sstpsvc.dll
ssText3d.scr ssdpsrv.dll ssh-agent.exe ssh-import-id-lp ssh.exe sstpsvc.mof
sscore.dll ssh ssh-argv0 ssh-keygen sshd
sscoreext.dll ssh-add ssh-copy-id ssh-keygen.exe sspicli.dll
ssdm.dll ssh-add.exe ssh-import-id ssh-keyscan sspisrv.dll
apt-get remove openssh-server
apt-get autoclean
apt-get install openssh-server
apt-get install net-tools
先备份,后修改哦
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bk
vi /etc/ssh/sshd_config
修改的内容如下
Port 22#远程端口为22 默认
ListenAddress 0.0.0.0#监听地址为0.0.0.0表示监听所有来访的ip
PasswordAuthentication yes#允许用户通过密码登陆
PermitRootLogin yes#允许root用户登陆
service ssh start
* Starting OpenBSD Secure Shell server sshd [ OK ]
查看ip地址
ifconfig
可以看到内网地址为172.18.225.147
eth0: flags=4163 mtu 1500
inet 172.18.225.147 netmask 255.255.240.0 broadcast 172.18.239.255
inet6 fe80::215:5dff:fe8b:2951 prefixlen 64 scopeid 0x20
ether 00:15:5d:8b:29:51 txqueuelen 1000 (Ethernet)
RX packets 100146 bytes 106041027 (106.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 55716 bytes 4041386 (4.0 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 16 bytes 800 (800.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16 bytes 800 (800.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
从ubuntu ping外网
ping www.baidu.com
可以看到没有问题
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=1 ttl=54 time=42.9 ms
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=2 ttl=54 time=37.3 ms
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=3 ttl=54 time=43.7 ms
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=4 ttl=54 time=39.8 ms
从windows ping ubuntu
在windows(同一局域网之下)的cmd中运行
ping 172.18.225.147:22
可以看到没有问题
Reply from 172.18.225.147: bytes=32 time<1ms TTL=64
Reply from 172.18.225.147: bytes=32 time<1ms TTL=64
Reply from 172.18.225.147: bytes=32 time<1ms TTL=64
Reply from 172.18.225.147: bytes=32 time<1ms TTL=64
这里使用的软件是mobaxterm,其他ssh登陆工具用法类似
输入ip地址,指定用户名和端口号
登陆后界面
添加 service ssh start
vi /etc/init.wsl