У меня есть две новые установки Ubuntu 16.04. На обоих ssh -V выдает
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g 1 Mar 2016
Когда я подключаюсь с аппарата A (ноутбук) к компьютеру B (удаленный), я сначала получаю соединение сразу, но он всегда закрывается через несколько минут, и я не могу установить соединение снова. Команда ssh ничего не пишет на экране, просто подождите, и ничего не происходит (значит, он простаивает и никогда не подключается). Если я назову ssh -vvv username@remotemachine, я получу
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g 1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "remotemachine" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 10.40.2.110 [10.40.2.110] port 22.
debug1: Connection established.
debug1: identity file /home/username/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/username/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/username/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/username/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/username/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/username/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/username/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/username/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
. Интересно, если теперь я перехожу на ssh на другой компьютер и подключаюсь к нему, он работает (по крайней мере, в первый раз). Когда он подключается в первый раз, ssh -vvv записывает сообщения, показанные выше:
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.2 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to remotemachine as 'klykov'
Интересно, какая машина неправильно настроена (клиент или сервер) и как я могу исправить эту проблему.
РЕЗУЛЬТАТ Проблема связана с конфликтом IP в локальной сети.
Тайм-ауты Idle обрабатываются как на сервере SSH, так и на клиенте.
Поэтому вам нужно настроить TCPKeepAlive, ServerAliveInterval в секундах на клиенте ssh_config и ClientAliveInterval на сервере /etc/ssh/sshd_config.
sudo nano /etc/ssh/sshd_config
[d2 ] раскомментировать или отредактировать TCPKeepAlive yes
ClientAliveInterval 600 # Timeout after 10 minutes, uncomment if no timeout
затем перезапустить службу (или эквивалентную)
/etc/init.d/ssh restart
на клиенте
nano .ssh/config
Host *
TCPKeepAlive=yes
ServerAliveInterval 600 # Same logic as above
Тайм-ауты Idle обрабатываются как на сервере SSH, так и на клиенте.
Поэтому вам нужно настроить TCPKeepAlive, ServerAliveInterval в секундах на клиенте ssh_config и ClientAliveInterval на сервере /etc/ssh/sshd_config.
sudo nano /etc/ssh/sshd_config
раскомментировать или отредактировать
TCPKeepAlive yes
ClientAliveInterval 600 # Timeout after 10 minutes, uncomment if no timeout
затем перезапустить службу (или эквивалентную)
/etc/init.d/ssh restart
на клиенте
nano .ssh/config
Host *
TCPKeepAlive=yes
ServerAliveInterval 600 # Same logic as above
Тайм-ауты Idle обрабатываются как на сервере SSH, так и на клиенте.
Поэтому вам нужно настроить TCPKeepAlive, ServerAliveInterval в секундах на клиенте ssh_config и ClientAliveInterval на сервере /etc/ssh/sshd_config.
sudo nano /etc/ssh/sshd_config
раскомментировать или отредактировать
TCPKeepAlive yes
ClientAliveInterval 600 # Timeout after 10 minutes, uncomment if no timeout
затем перезапустить службу (или эквивалентную)
/etc/init.d/ssh restart
на клиенте
nano .ssh/config
Host *
TCPKeepAlive=yes
ServerAliveInterval 600 # Same logic as above