How to Keep Alive SSH Sessions
To enable the keep alive system-wide (root access required), edit /etc/ssh/ssh_config; to set the settings for just your user, edit ~/.ssh/config (create the file if it doesn’t exist). Insert the following:
Host * ServerAliveInterval 300 ServerAliveCountMax 2
You can also make your OpenSSH server keep alive all connections with clients by adding the following to /etc/ssh/sshd_config:
ClientAliveInterval 300 ClientAliveCountMax 2
Add timestamp to SSH verbose logs
ssh -v 192.168.0.151 exit 2>&1 | while read line; do printf '[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$line"; done
Store SSH client VERBOSE logs into log file
ssh -v 192.168.0.151 exit 2>&1 | while read line; do printf '[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$line"; done > "/tmp/ssh-debug.log"
How does 'ssh <destination> exit' terminate the session?
The exit executed by the remote shell would terminate that shell. In
the case when true is executed, the remote shell would terminate due
to not having any further commands to execute, but exit would
terminate it even if there were further commands afterwards (as in any
In the simple case where the SSH session is only for executing a set
of commands (where it does not set up tunnels or use connection
sharing), the session would terminate when the remote shell
terminates, no matter how the remote shell terminates (either by exit
or by some error, or receiving a HUP signal, or by simply reaching the
end of the script).
Note that the manual says "[...] and all X11 and TCP connections have
been closed". This means that the connection may not terminate just
because the remote shell has terminated. This will be the case when
you, for example, are using connection sharing with ssh -M and ssh -S
(or the ControlMaster setting in ~/.ssh/config; see man ssh and man
ssh_config). I assume that SSH tunnels would also keep the SSH session
alive until they are explicitly closed.
To truly terminate the SSH connection, you may send the exit control
command using ssh -O exit user@host. This would terminate all shared
SSH sessions to user@host.
SSHFS is available for most Linux distributions. On Ubuntu, you can install it using apt.
First, use apt update to refresh your package sources:
sudo apt update
Then, use apt install to install the sshfs package.
sudo apt install sshfs
Mounting the Remote Filesystem
Create a subdirectory within /mnt called droplet using the mkdir command:
sudo mkdir /mnt/droplet
You can now mount a remote directory using sshfs.
sudo sshfs -o allow_other,default_permissions sammy@your_other_server:~/ /mnt/droplet
If you no longer need this mount, you can unmount it with the umount command:
sudo umount /mnt/droplet
sshfs remote host has disconnected
Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp
Both sftp-server and internal-sftp are part of OpenSSH. The sftp-server is a standalone binary. The internal-sftp is just a configuration keyword that tells sshd to use the SFTP server code built-into the sshd, instead of running another process (what would typically be the sftp-server).
The internal-sftp was added much later (OpenSSH 4.9p1 in 2008?) than the standalone sftp-server binary. But it is the default by now. The sftp-server is now redundant and is kept probably for a backward compatibility.
I believe there's no reason to use the sftp-server for new installations.