一般来说,对Linux的服务器,我们会使用ssh和ftp来进行交互,通常是xshell以及xftp两个软件。
但是很多时候,我们可能并没有Linux服务器,这个时候其实自己的个人电脑也可以勉强成为Linux服务器:
如果要与你的windows的Ubuntu子系统进行交互,首先必须要知道windows的Ubuntu子系统的IP地址。
因为我们开启的windows的Ubuntu子系统,其实就是Windows10的一个可执行linux命令的窗口,所以是同一个ip地址,在Ubuntu子系统的终端使用sudo下载安装两个工具包:
sudo apt install net-tools
sudo apt-get install openssh-server
然后在Ubuntu里面使用 ifconfig 命令查看,如下:
jmzeng@DESKTOP-D7COBEK:~$ ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 1500
inet 127.0.0.1 netmask 255.0.0.0
wifi0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.108 netmask 255.255.255.0 broadcast 192.168.0.255
在windows电脑使用ipconfig查看
IPv4 地址 . . . . . . . . . . . . : 192.168.0.108
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . : 192.168.0.1
如果你是使用自己的windows电脑来连接它内部的Ubuntu子系统,那就使用 127.0.0.1,如果你是使用跟你的windows电脑在同一个路由器下面的其它电脑来ssh连接它,就使用这个windows电脑的内网IP即可。
因为windows自己的22端口被占用,所以必须要修改这个windows的Ubuntu子系统ssh协议的端口,我这里参考 https://www.jianshu.com/p/bc38ed12da1d/ 的配置代码:
# 1.安装ssh(一般不需要这步,前面已经安装过了)
sudo apt-get install openssh-server
# 2.修改配置文件
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sudo vim /etc/ssh/sshd_config
#=======(修改以下选项内容)=========#
Port 222
AddressFamily any
ListenAddress 0.0.0.0
PasswordAuthentication yes
#================================#
# 3.启动ssh
sudo service ssh restart
# 4.如果提示“sshd error: could not load host key”,则用下面的命令重新生成
rm /etc/ssh/ssh*key
dpkg-reconfigure openssh-server
然后就可以很容易使用xshell软件连接它了,因为是自己连接自己,所以使用 127.0.0.1 这个IP即可,它代表localhost电脑,就是自己的电脑,设置如下:
不过,一般来说,自己的windows电脑没有不要去连接自己的windows的Ubuntu子系统,因为本来就可以直接登录终端。成功连接后如下:
大概率是同一个路由器的其它工作电脑来连接它,就使用 192.168.0.108 这样的内网IP 咯。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有