首页 > 系统相关 >windows10安装wsl的centos7版本,并启动ssh服务远程访问

windows10安装wsl的centos7版本,并启动ssh服务远程访问

时间:2022-11-07 10:25:27浏览次数:42  
标签:sshd https windows10 wsl centos7 etc host ssh key

1.安装wsl的centos版本

wsl是什么就不多说了,不清楚的自己去谷歌吧。也可以参考下面几篇文章:

[https://learn.microsoft.com/zh-cn/windows/wsl/install-manual](microsoft官方文档)
[https://zhuanlan.zhihu.com/p/146545159]([安利] WSL Linux 子系统,真香!完整实操)
[https://www.jianshu.com/p/0a102c4bb3a2](WSL win10子系统linux-ubuntu 安装 开机启动ssh服务 secureCRT连接 换源 与windows系统文件交互)
而windows store商店的linux版本,能用的只有ubuntu版本。而生产环境服务器大部分都是centos版本,以前用虚拟机也基本都是centos版本,ubuntu确实是用不习惯。安装centos需要手动下载安装包。
[https://github.com/mishamosher/CentOS-WSL](CentOS-WSL)下面随便给几个cdn加速的github地址,访问不了github的自取。
wget https://gh.gh2233.ml/https://github.com/mishamosher/CentOS-WSL/releases/download/7.9-2111/CentOS7.zip
wget https://github.91chi.fun/https://github.com/mishamosher/CentOS-WSL/releases/download/7.9-2111/CentOS7.zip
wget https://download.fastgit.org/mishamosher/CentOS-WSL/releases/download/7.9-2111/CentOS7.zip


下载完成之后,直接解压,双击CentOS7.exe自动安装完成。

2.开启ssh服务

wsl是无法用systemctl启动ssh的,因此,需要自己写脚本vi /etc/init.d/sshd

#!/bin/sh
# Start/stop/restart the secure shell server:

sshd_start() {
  # Create host keys if needed.
  if [ ! -r /etc/ssh/ssh_host_key ]; then
    /usr/bin/ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key -N '' 
  fi
  if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
    /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
  fi
  if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
    /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
  fi
  if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
    /usr/bin/ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key-N ''
  fi
  if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
    /usr/bin/ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key-N ''
  fi
  /usr/sbin/sshd -f /etc/ssh/sshd_config
}

sshd_stop() {
  killall sshd
}

sshd_restart() {
  if [ -r /var/run/sshd.pid ]; then
    echo "WARNING: killing listener process only.  To kill every sshd process, you must"
    echo "         use 'rc.sshd stop'.  'rc.sshd restart' kills only the parent sshd to"
    echo "         allow an admin logged in through sshd to use 'rc.sshd restart' without"
    echo "         being cut off.  If sshd has been upgraded, new connections will now"
    echo "         use the new version, which should be a safe enough approach."
    kill `cat /var/run/sshd.pid`
  else
    killall sshd
  fi
  sleep 1
  sshd_start
}

case "$1" in
'start')
  sshd_start
  ;;
'stop')
  sshd_stop
  ;;
'restart')
  sshd_restart
  ;;
*)
  echo "usage $0 start|stop|restart"
esac

然后,修改sshd服务启动配置文件
vi /etc/ssh/sshd_config

#允许root用户登录
PermitRootLogin yes
#服务端口,为了不和windows及其它wsl子系统冲突,手动指定一个
Port 12308
#监听地址,如果需要远程机器连接
ListenAddress 0.0.0.0

启动sshd,查看服务已经启动

/etc/init.d/sshd start
ps -ef|grep ssh

windows下面win+r打开cmd,输入netstat -ano|findstr "12308",查看端口,发现已经启动

之后,就可以配合vscode,远程连接到windows下面的centos进行远程代码开发,爽歪歪。

标签:sshd,https,windows10,wsl,centos7,etc,host,ssh,key
From: https://www.cnblogs.com/yang417/p/16865082.html

相关文章

  • CentOS7编译安装haproxy-2.6.6
    创建用户并安装依赖包#selinux会影响haproxy启动,会有'cannotbindUNIXsocket(Permissiondenied)'的报错,请关闭它除非你知道设置selinux规则sed-i'/SELINUX/s/enf......
  • Centos7安装MySQL
    一、卸载系统自带的mariadb1、查看系统自带的mariadbrpm-qa|grepmariadb   2、卸载rpm-e--nodeps mariadb-libs-5.5.68-1.el7.x86_64二、mysql安装1、......
  • SpringCloud (五) - 云服务器Centos7.6,安装JDK,Maven,Mysql,Redis
    1、购买云服务器购买地址:https://cloud.tencent.com/act/pro/2022double11_warmup后面的环境都是基于此环境Centos7.6;2、安装SecureCRT和SecureFX2.1SecureCRT教......
  • VirtualBox 下 CentOS7 静态 IP 的配置 → 多次踩坑总结,蚌埠住了!
    开心一刻一个消化不良的病人向医生抱怨:我近来很不正常,吃什么拉什么,吃黄瓜拉黄瓜,吃西瓜拉西瓜,怎样才能恢复正常呢?医生沉默片刻:那你只能吃屎了环境准备Virt......
  • WSL2 通过 CLASH 配置
    vim ~/.zshrc exporthostip=$(cat/etc/resolv.conf|grep-oP'(?<=nameserver\).*')exporthttps_proxy="http://${hostip}:7890"exporthttp_proxy="http://${hos......
  • windows10安装dlib+python3.9
     1、whl安装注意,仅支持特定版本,请检查pip所支持的版本是否一致dlib-19.23.0-cp39-cp39-win_amd64.whlhttps://gitee.com/billyme/python-dlib/raw/master/dist/dlib-......
  • WSL允许用其他电脑ssh连接
    WSL允许ssh描述在另一台机器上用ssh连接WSL;原因解决首先在linux中启动SSH连接支持:#客户端 sudoapt-getinstallopenssh-client #服务器 sud......
  • windows10安装pip
    1、下载下载路径  https://pypi.org/project/pip/#files下载:  下载完成后解压到本地的软件安装目录,如下所示:  2、安装打开cmd,进入到解压包存放的路径:  ......
  • WSL2 Ubuntu固定IP,开机启动SSH
    1.设置SSH安装wsl2Ubuntu,后无法启动SSH1.1出现的错误包括:a.start-stop-daemon:unabletosetgidto0(Operationnotpermitted)b.*StartingOpenBSDSecur......
  • CentOS7命令行创建LVM逻辑卷
    概述当初在安装CentOS7系统时没有使用LVM,后期安装应用后磁盘空间不够使用,在不跨服务器迁移数据的情况下解决磁盘空间问题。1.安装lvm命令yuminstall-ysystem-storage-man......