0

Basically I have enabled a SSH server in Kali WSL Linux.

The problem is that when I do ssh root@192.168.0.225 from Windows and provide the password, it works just fine and the connection succeeds.

When I do it from the Internet, and do ssh root@PublicIP, it asks for the password and then it fails.

I have enabled port forwarding in my router to enable SSH access on port 22 and also have enabled PermitRootLogin: Yes.

When doing ssh from the Internet, the output of the command ssh -vvv root@x.x.x.x is the following:

debug1: Trying private key: C:\\Users\\username/.ssh/id_dsa
debug3: GetFileAttributesExW with last error 2
debug3: no such identity: C:\\Users\\username/.ssh/id_dsa: No such file or directory
debug1: Trying private key: C:\\Users\\username/.ssh/id_ecdsa
debug3: GetFileAttributesExW with last error 2
debug3: no such identity: C:\\Users\\username/.ssh/id_ecdsa: No such file or     directory
debug1: Trying private key: C:\\Users\\username/.ssh/id_ed25519
debug3: GetFileAttributesExW with last error 2
debug3: no such identity: C:\\Users\\username/.ssh/id_ed25519: No such file or     directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
debug3: failed to open file:/dev/tty error:3
debug1: read_passphrase: can't open /dev/tty: No such file or directory

The server /var/log/auth.log output is:

Aug 19 17:17:01 kali CRON[1427]: pam_unix(cron:session): session opened for user root by (uid=0)
Aug 19 17:17:01 kali CRON[1427]: pam_unix(cron:session): session closed for user root
Aug 19 17:21:13 kali systemd-logind[553]: New seat seat0.
Aug 19 17:21:13 kali systemd-logind[553]: Watching system buttons on /dev/input/event5 (Power Button)
Aug 19 17:21:13 kali systemd-logind[553]: Watching system buttons on /dev/input/event0 (AT Translated Set 2 keyboard)
Aug 19 17:21:15 kali sshd[586]: Server listening on 0.0.0.0 port 22.
Aug 19 17:21:15 kali sshd[586]: Server listening on :: port 22.
Aug 19 17:21:16 kali gdm-launch-environment]: pam_unix(gdm-launch-environment:session): session opened for user Debian-gdm by (uid=0)
Aug 19 17:21:16 kali systemd-logind[553]: New session c1 of user Debian-gdm.
Aug 19 17:21:16 kali systemd: pam_unix(systemd-user:session): session opened for user Debian-gdm by (uid=0)
Aug 19 17:21:25 kali polkitd(authority=local): Registered Authentication Agent for unix-session:c1 (system bus name :1.16 [/usr/bin/gnome-shell], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
Aug 19 17:21:27 kali realmd[785]: Loaded settings from: /usr/lib/realmd/realmd-defaults.conf /usr/lib/realmd/realmd-distro.conf
Aug 19 17:21:27 kali realmd[785]: holding daemon: startup
Aug 19 17:21:27 kali realmd[785]: starting service
Aug 19 17:21:27 kali realmd[785]: connected to bus
Aug 19 17:21:27 kali realmd[785]: released daemon: startup
Aug 19 17:21:27 kali realmd[785]: claimed name on bus: org.freedesktop.realmd
Aug 19 17:21:44 kali gdm-password]: pam_unix(gdm-password:session): session opened for user root by (uid=0)
Aug 19 17:21:44 kali systemd: pam_unix(systemd-user:session): session opened for user root by (uid=0)
Aug 19 17:21:44 kali systemd-logind[553]: New session 2 of user root.
Aug 19 17:21:47 kali polkitd(authority=local): Registered Authentication Agent     for unix-session:2 (system bus name :1.55 [/usr/bin/gnome-shell], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
Aug 19 17:22:28 kali realmd[785]: quitting realmd service after timeout
Aug 19 17:22:28 kali realmd[785]: stopping service
Aug 19 17:23:03 kali sshd[1269]: Connection closed by 192.168.0.13 port 57122     [preauth]
Aug 19 17:24:35 kali sudo:     root : TTY=pts/0 ; PWD=/root ; USER=root ;     COMMAND=/usr/bin/passwd
Aug 19 17:24:35 kali sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
Aug 19 17:24:37 kali passwd[1284]: pam_unix(passwd:chauthtok): password changed for root
Aug 19 17:24:37 kali passwd[1284]: gkr-pam: couldn't update the login keyring password: no old password was entered
Aug 19 17:24:37 kali sudo: pam_unix(sudo:session): session closed for user     root
Aug 19 17:25:01 kali CRON[1287]: pam_unix(cron:session): session opened for user     root by (uid=0)
Aug 19 17:25:01 kali CRON[1287]: pam_unix(cron:session): session closed for user root
Aug 19 17:26:11 kali sshd[1290]: Accepted password for root from 192.168.0.13 port 57190 ssh2
Aug 19 17:26:11 kali sshd[1290]: pam_unix(sshd:session): session opened for user root by (uid=0)
Aug 19 17:26:11 kali systemd-logind[553]: New session 5 of user root.
Aug 19 17:28:04 kali passwd[1307]: pam_unix(passwd:chauthtok): password changed for sshd
Aug 19 17:28:04 kali passwd[1307]: gkr-pam: couldn't update the login keyring password: no old password was entered
Aug 19 17:28:14 kali sshd[1290]: pam_unix(sshd:session): session closed for user root
Aug 19 17:28:14 kali systemd-logind[553]: Removed session 5.
Aug 19 17:35:01 kali CRON[1328]: pam_unix(cron:session): session opened for user root by (uid=0)
Aug 19 17:35:01 kali CRON[1328]: pam_unix(cron:session): session closed for user root

How can I do the SSH connection successfully?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Temmp
  • 29

1 Answers1

2

Any flavour of Windows Subsystem for Linux in Windows is not exactly your regular off-the-mill Linux running. (see the related question link at the end for more data)

Remote SSH needs pseudo-terminals support for working properly. According to these two articles, it has only been added very recently in Windows 14361 Insider preview Update in June. It is not yet available to the general public yet, so remote SSH won´t work in any WSL Linux flavour, for now.

It seems WSL Ubuntu is preparing for that, and Kali often takes a while to catch up.

Furthermore, WSL does not have special privileges and is just any other regular Windows user/process. Services/daemons in WSL do not keep running after you close the WSL command line boxes, all processes are killed.

You would be better running Linux in a VM if you have to run (permanent) Linux services.

About the pseudo-terminals/pty support, see:

Tmux Support arrives for Bash on Ubuntu on Windows

Windows 10 build 14361 for PC: Everything you need to know

In Windows 10 build 14361, we've added Pseudo Terminal support to Windows Subsystem for Linux (WSL)

See related question: Attempting to run a regular tunnel in Debian version 9.5 Linux

See also: What are pseudo terminals (pty/tty)?

PS. I do not ignore that there are convoluted setup/hacks to try to run permanent services on WLS, that rely on WSL being intimately tied to Windows. They are ugly and I doubt their reliability.

It is also still unknown if the new WSL pty implementation will allow OpenSSH to work.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
  • 1
    the 14361 Update is not very recently, it was an insider preview in June 2016, since the Spring Update 2018, Microsoft added the concept of background tasks for WSL – Nordlys Jeger Aug 20 '18 at 04:20
  • @NordlysJeger Thanks, I was seeing something was amiss, but I am not a Windows regular. Changed the answer. – Rui F Ribeiro Aug 20 '18 at 04:24