How to get all SSH connections to the Linux server

SSH (Secure Shell) provides an encrypted channel for logging into another computer over a network, executing commands on a remote computer, and moving files from one computer to another.

You may want to know all users on your server, for example, if cpu load grows.

If you can use modern utility ss try this:

ss -o state established '( dport = :ssh or sport = :ssh )'

Or you can do it “old style” by the command netstat:

netstat -tnpa | grep 'ESTABLISHED.*sshd'

Also you can see ssh connections’ file descriptors:

lsof -n -a -itcp -stcp:established -c sshd

And of cause you can see all logged in users: