wsl按照openssh失败

1. 本机无密码登录

[root@QingYuan-PC sbin]# ssh localhost
ssh: connect to host localhost port 22: Connection refused

因为没有按照openssh-server 解决办法:

yum install openssh-server

2. 启动openssh-server

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
chmod +x /usr/bin/systemctl

https://github.com/DDoSolitary/LxRunOffline/issues/88

3. 再次启动openssh-server

[root@QingYuan-PC Qingyuan_Qu]# systemctl status sshd
sshd.service - OpenSSH server daemon
    Loaded: loaded (/usr/lib/systemd/system/sshd.service, enabled)
    Active: failed (failed)

那好,咱们看一下服务化启动配置文件,可以看到配置文件为/etc/sysconfig/sshd

[root@QingYuan-PC sbin]# cat /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.service
Wants=sshd-keygen.service

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

好,咱们拿着sshd程序 + 配置文件启动一下,看看提示啥:

[root@QingYuan-PC sbin]# /usr/sbin/sshd  -f /etc/sysconfig/sshd
/etc/sysconfig/sshd: line 14: Bad configuration option: SSH_USE_STRONG_RNG
/etc/sysconfig/sshd: terminating, 1 bad configuration options

通过上面可以看到,提示配置项错误;
看一下配置文件:

[root@QingYuan-PC sbin]# cat /etc/sysconfig/sshd
# Configuration file for the sshd service.
SSH_USE_STRONG_RNG=0

坏了,不知道往后咋整了… …
没事儿,百度百度吧
后来发现,在/etc/ssh/下面还有配置文件

[root@QingYuan-PC sbin]# cd /etc/ssh/
[root@QingYuan-PC ssh]# ll
total 580
-rw-r--r-- 1 root root 581843 Aug  9  2019 moduli
-rw-r--r-- 1 root root   2276 Aug  9  2019 ssh_config
-rw------- 1 root root   3907 Aug  9  2019 sshd_config

那我换配置文件启动试一下

[root@QingYuan-PC ssh]# /usr/sbin/sshd  -f /etc/ssh/sshd_config
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key
sshd: no hostkeys available -- exiting.

好吧,继续百度… …

[sshd 启动后 出现:Could not load host key: /etc/ssh/ssh_host_rsa_key]
https://www.cnblogs.com/xuyaowen/p/ssh-keygen.html

注意,上面引文的作者把生成rsakey的命令写错了。

[root@QingYuan-PC ssh]# ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key

让本机无密码登录

[root@QingYuan-PC .ssh]#  cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
[root@QingYuan-PC .ssh]# ll
total 4
-rw-r--r-- 1 root root  398 Aug 24 18:09 authorized_keys
-rw------- 1 root root 1679 Jul 31 21:04 id_rsa
-rw-r--r-- 1 root root  398 Jul 31 21:04 id_rsa.pub
-rw-r--r-- 1 root root  171 Aug 24 18:08 known_hosts
[root@QingYuan-PC .ssh]# chmod 0600 ~/.ssh/authorized_keys
[root@QingYuan-PC .ssh]# ssh localhost
Last failed login: Tue Aug 24 18:06:39 CST 2021 from localhost on ssh:notty
There were 2 failed login attempts since the last successful login.

修改服务化配置文件

[root@QingYuan-PC .ssh]# vim /usr/lib/systemd/system/sshd.service
修改下面这行,指定/etc/ssh/目录下的配置文件
EnvironmentFile=/etc/ssh/sshd_config

保存退出

[root@QingYuan-PC .ssh]# systemctl start sshd
[root@QingYuan-PC .ssh]# systemctl status sshd
sshd.service - OpenSSH server daemon
    Loaded: loaded (/usr/lib/systemd/system/sshd.service, enabled)
    Active: active (running)

active有没有!!!

本机无密码登录

  $ ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
  $ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
  $ chmod 0600 ~/.ssh/authorized_keys
[root@QingYuan-PC .ssh]# ssh localhost
Last login: Tue Aug 24 18:09:18 2021 from localhost
[root@QingYuan-PC ~]#

The End~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值