WSL 安装Centos7

卸载

wsl --shutdown

wsl --list

wsl --unregister CentOS7

设置内存

C:\Users\whirl的.wslconfig

[wsl2]

memory=10GB

swap=0

localhostForwarding=true

更新yum

yum update

yum install vim -y

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 22
#监听地址,如果需要远程机器连接
ListenAddress 0.0.0.0

chmod +777 /etc/init.d/sshd

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

/etc/init.d/sshd start

如果启动出现报错error: Could not load host key: /etc/ssh/ssh_host_ed25519_key,

/usr/sbin/sshd-keygen -A

ps -ef|grep ssh

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

修改ssh的密码

[root@whirl ~]# passwd
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

设置systemctl,解决Failed to get D-Bus connection: Operation not permitted

mv /usr/bin/systemctl /usr/bin/systemctl.old

curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py > /usr/bin/systemctl

cat /mnt/d/KGSystem/部署文件/systemctl.py > /usr/bin/systemctl

chmod +x /usr/bin/systemctl

cp /mnt/d/KGSystem/部署文件/sealos 方式/docker_onekey_install.zip > /root/docker

你可能感兴趣的:(Linux,linux)