Esta resposta funcionou para que eu conseguisse ssh no subsistema Linux a partir do localhost, mas não era suficiente para me deixar acessar remotamente.
Eu tenho:
- Executar o item do menu Iniciar Bash como administrador;
- feitas todas as modificações de
/etc/ssh/sshd_config
recomendadas na resposta vinculada acima;
- Alterado da porta 22 para a porta 2222 para tentar evitar problemas de segurança no uso de portas do sistema;
- Confirmado que o
ssh trey@localhost -p 2222
funciona conforme esperado.
No entanto, isso não me permite fazer login de outros hosts na minha LAN. Se eu parar o serviço ( sudo service ssh stop
) e executar no modo de depuração ( sudo /usr/sbin/sshd -d
), recebo a seguinte saída:
sudo: unable to resolve host SYCORAX
debug1: sshd version OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: private host key: #0 type 1 RSA
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type DSA
debug1: private host key: #1 type 2 DSA
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type ECDSA
debug1: private host key: #2 type 3 ECDSA
debug1: private host key: #3 type 4 ED25519
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-d'
Set /proc/self/oom_adj from 0 to -17
debug1: Bind to port 2222 on 0.0.0.0.
Server listening on 0.0.0.0 port 2222.
debug1: Bind to port 2222 on ::.
Bind to port 2222 on :: failed: Address already in use.
Ele fica lá e não muda se eu tentar ssh de outro host usando o endereço IP da Ethernet (que é pingável). Se eu tentar ssh do localhost, no entanto, continua:
debug1: Server will not fork when running in debugging mode.
debug1: rexec start in 4 out 4 newsock 4 pipe -1 sock 7
debug1: inetd sockets after dupping: 3, 3
Connection from 127.0.0.1 port 60453 on 127.0.0.1 port 2222
debug1: Client protocol version 2.0; client software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
debug1: list_hostkey_types: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ssh-ed25519
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: client->server aes128-ctr [email protected] none
debug1: kex: server->client aes128-ctr [email protected] none
debug1: expecting SSH2_MSG_KEX_ECDH_INIT
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: KEX done
debug1: userauth-request for user trey service ssh-connection method none
debug1: attempt 0 failures 0
debug1: PAM: initializing for "trey"
debug1: PAM: setting PAM_RHOST to "localhost"
debug1: PAM: setting PAM_TTY to "ssh"
Failed none for trey from 127.0.0.1 port 60453 ssh2
debug1: userauth-request for user trey service ssh-connection method password
debug1: attempt 1 failures 0
debug1: PAM: password authentication accepted for trey
Accepted password for trey from 127.0.0.1 port 60453 ssh2
debug1: do_pam_account: called
debug1: PAM: establishing credentials
debug1: Entering interactive session for SSH2.
debug1: server_init_dispatch_20
debug1: server_input_channel_open: ctype session rchan 0 win 1048576 max 16384
debug1: input_session_request
debug1: channel 0: new [server-session]
debug1: session_new: session 0
debug1: session_open: channel 0
debug1: session_open: session 0: link with channel 0
debug1: server_input_channel_open: confirm session
debug1: server_input_global_request: rtype [email protected] want_reply 0
debug1: server_input_channel_req: channel 0 request pty-req reply 1
debug1: session_by_channel: session 0 channel 0
debug1: session_input_channel_req: session 0 req pty-req
debug1: Allocating pty.
debug1: session_pty_req: session 0 alloc /dev/pts/0
debug1: SELinux support disabled
debug1: server_input_channel_req: channel 0 request env reply 0
debug1: session_by_channel: session 0 channel 0
debug1: session_input_channel_req: session 0 req env
debug1: server_input_channel_req: channel 0 request shell reply 1
debug1: session_by_channel: session 0 channel 0
debug1: session_input_channel_req: session 0 req shell
Starting session: shell on pts/0 for trey from 127.0.0.1 port 60453
debug1: Setting controlling tty using TIOCSCTTY.
E eu entro com sucesso no cliente SSH local, que imprime as seguintes mensagens de depuração:
trey@localhost's password:
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 3.4.0+ x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Sat Aug 27 14:51:29 2016 from localhost
debug1: PAM: reinitializing credentials
debug1: permanently_set_uid: 1000/1000
debug1: Unable to open session: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
Environment:
LANG=en_US.UTF-8
USER=trey
LOGNAME=trey
HOME=/home/trey
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
MAIL=/var/mail/trey
SHELL=/bin/bash
SSH_CLIENT=127.0.0.1 60453 2222
SSH_CONNECTION=127.0.0.1 60453 127.0.0.1 2222
SSH_TTY=/dev/pts/0
TERM=xterm
trey@SYCORAX:~$
Depois de fazer o logout daquele ssh local, recebo o seguinte do processo sshd antes de sair:
debug1: Received SIGCHLD.
debug1: session_by_pid: pid 677
debug1: session_exit_message: session 0 channel 0 pid 677
debug1: session_exit_message: release channel 0
debug1: session_pty_cleanup: session 0 release /dev/pts/0
syslogin_perform_logout: logout() returned an error
debug1: session_by_channel: session 0 channel 0
debug1: session_close_by_channel: channel 0 child 0
debug1: session_close: session 0 pid 0
debug1: channel 0: free: server-session, nchannels 1
Received disconnect from 127.0.0.1: 11: disconnected by user
debug1: do_cleanup
debug1: PAM: cleanup
debug1: PAM: closing session
debug1: PAM: deleting credentials
debug1: audit_event: unhandled event 12
Curiosamente, não tenho nenhum problema ssh'ing (seja local ou remotamente) em um Hyper-V virtual rodando o Ubuntu 16 no mesmo host com o sshd rodando na porta 22. (É claro , o convidado da VM do Hyper-V está em um endereço IP diferente do host do Windows.)
O Telnet para a porta 2222 também não tem êxito.
Eu suspeito que a incapacidade de sshd se ligar à porta IPv6 é a chave para entender o que está acontecendo, mas as ferramentas que eu conheço (tanto do lado do Windows quanto do Linux) não mostram qualquer coisa ligada à porta 2222 no TCP v4 ou v6.