enable ssh debugging

How to Enable Debugging Mode in SSH

SSH (Secure Shell) is one of the most popular ways for developers and system administrators to connect to remote systems and do their work. However, sometimes you may not be able to connect to a remote server via SSH. At such times, it is useful if you can see the error and what is going on during connection. For this purpose, you need to enable debugging mode in SSH. It allows you to see what happens when you execute SSH command to connect to remote server. In this article, we will learn how to enable debugging mode in SSH.


How to Enable Debugging Mode in SSH

Here are the steps to enable debugging mode in SSH.


Enable SSH debugging in Client

Basically you need to use -v option with SSH client, to run SSH in debug mode, which will print debugging information during connection progress. It is useful for debugging authentication and network issues during SSH connection. Here is an example of command.

$ ssh -v test_user@54.43.32.21

Here is the sample output you will see.

OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g-fips  1 Mar 2022
debug1: Reading configuration data /home/test_user/.ssh/config
debug1: /home/test_user/.ssh/config line 18: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 54.43.32.21 [54.43.32.21] port 22.
debug1: Connection established.
debug1: identity file /home/test_user/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/test_user/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/test_user/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/test_user/.ssh/id_dsa-cert type -1
...

It is interesting to note that there different levels of verbosity in SSH debugging mode. For example, if you use multiple -v flags, it will increase the verbosity. Here are a couple of commands to enable additional (level 2 and level 3) verbosity in SSH debugging.

$ ssh -vv test_user@54.43.32.21
$ ssh -vvv test_user@54.43.32.21


Enable SSH debugging from Server

You can also enable debugging from SSH server side using -d flag. For this purpose, you need to stop SSH daemon and restart it with debug flags.

# service sshd stop
OR

# /etc/init.d/sshd stop

Now start SSH service with -d flag.

# /usr/sbin/sshd -d

Similar to the client side, by using multiple -d options you can increase the verbosity of debugging information.

But please note, when you enable debugging in SSH server, it will accept only one connection at a time.

So it is advisable to always use SSH debugging on the client side instead of using it on server side.

In this article, we will learn how to enable debugging mode in SSH. It is a very useful feature to understand why SSH connection is failing or you getting disconnected. As mentioned above, it is better to enable SSH debugging from client side instead of server side.

Also read:

How to Copy Column to Another Column in MySQL
How to Add Header in CSV File Using Shell Script
How to Create Yum Repository in RHEL Using ISO Image
How to Create Local Yum Repository in RHEL/CentOS
How to List Files Installed from RPM or DEB Package

Leave a Reply

Your email address will not be published. Required fields are marked *