在 Windows Linux子系统(WSL:ubuntu:20.4 LTS)上安装 OpenSSH-Server 通过 SSH 远程访问
直接通过 SSH 登录时提示错误如下:
shell
1 2
$ ssh akiya@localhost ssh: connect to host localhost port 22: Connection refused
怀疑是没有安装 OpenSSH-Server,接着便使用命令安装
shell
1 2 3 4 5
$ sudo apt install openssh-server Reading package lists... Done Building dependency tree Reading state information... Done openssh-server is already the newest version (1:8.2p1-4ubuntu0.1).
$ sudo service ssh restart * Restarting OpenBSD Secure Shell server sshd [ OK ]
现在我们可以使用 ssh 登录 WSL 了
shell
1 2 3 4
$ ssh akiya@localhost The authenticity of host 'localhost (127.0.0.1)' can't be established. RSA key fingerprint is SHA256:IE0uKLebsAS9/FbuQEHq8sCkauJUwkj0hDlpAhtn0C0. Are you sure you want to continue connecting (yes/no/[fingerprint])?
不过需要使用 SSH Key 登录,不然会报错如下:
shell
1 2 3 4 5 6
# ssh akiya@192.168.1.184 The authenticity of host '192.168.1.184 (192.168.1.184)' can't be established. RSA key fingerprint is SHA256:kupZMJjigDbmvj9Sj3liyzp3KgVzRViuXO6SESX+l5o. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '192.168.1.184' (RSA) to the list of known hosts. akiya@192.168.1.184: Permission denied (publickey).