Configuration and record related to SSH

Image credit: SSH logo

Table of Contents

The commands will be used herein

Start SSH servicesudo service ssh start
Restart SSH servicesudo service ssh restart
Run SSH Daemon(For Msys2)/usr/bin/sshd
Run SSH Daemon(For Termux)sshd
Run SSH Daemon(For Termux with debug mode)sshd -d

Problem solving for SSH connection interruption

After the SSH is established remotely, if it does not operate or perform data exchanges via SSH, in the case of the default SSH configuration, the connection interruption will occur sometimes. The error message is as follow.

  Write failed: Broken pipe

Maybe you can solve this issue through changing the configuration files of SSH client or server.

Change SSH client settings

Open the SSH client configuration file /etc/ssh/ssh_config (for all users) or ~/.ssh/config (for current user only) and add or modify the current settings as follows.

  ServerAliveInterval 15
  ServerAliveCountMax 10

When finish modification, you may need to restart SSH service. At this time, SSH client send to server 10 responses every 15 seconds, if still no responses then interrupt the connection.

Change SSH server settings

Open the SSH server configuration file /etc/ssh/sshd_config, and add or modify the current settings as follows.

  ClientAliveInterval 30
  ClientAliveCountMax 5

Same as the previous, when finish modification restart SSH service. At this time, SSH server send to client 5 responses every 30 seconds, if still no responses then interrupt the connection.


Tools such as Tmux or Screen are good options when working with SSH remote connection. Because of that even if the SSH connection is interrupt, as long as the remote server is still working properly, you can touch the session you used while reconnecting to the remote server, this is very convenient for recover the previous working environment.

Start SSH service on an Android device

Install Termux app through Google Play store. After the installation is complete, run Termux app, and execute the following command to install OpenSSH.

  apt install openssh

Create a key file by executing the following commands after OpenSSH installation is complete. It is necessary to note that the permissions should be set to only allow the current user to read and write, Too open permission settings will cause remote connection rejection.

  cat ~/.ssh/ > ~/.ssh/authorized_keys
  chmod 600 ~/.ssh/authorized_keys
  chmod 700 ~/.ssh

After the key file is created, run sshd in Termux app to run SSH Daemon. copy the private key file ~/.ssh/id_rsa to any other client device in the LAN, then execute the following command on this client device to connect the SSH server which on the Android device.

  ssh ip.address -p 8022 -i /path_to/id_rsa

Note: The key files including =id_rsa= which copied to the client, all need to pay attention to the permission setting. Please refer to the settings for SSH server.

Other SSH Problems

no hostkeys

  • Error message

  sshd: no hostkeys available
  • Solution

  sudo ssh-keygen -A

could not open connection

  • Error message

  Could not open a connection to your authentication agent.
  • Solution

  eval "$(ssh-agent -s)" # for bash / zsh
  eval (ssh-agent -c)    # for fish

Improve SSH server security

Open the configuration file /etc/ssh/sshd_config, and add or modify the current settings as follows.

  Port ????
  PasswordAuthentication no

Set the port number to other numbers other than 22, and disable using password when establish a SSH connection.

Edit this page

Xin Li
Xin Li

Research in areas such as machine learning, deep learning, and artificial intelligence applications, specialize in priority sampling and learning algorithm for non-uniform data and offset data.Learn more

comments powered by Disqus