Show non-truncated usernames of users connected to sshd server in terminal?
3
votes
1
answer
198
views
On my Ubuntu server, I find it very useful that
netstat -tulpn
also shows the username connected to sshd
(apparently, this username printing is specifically for sshd
) - unfortunately, this printout is also truncated:
$ sudo netstat -tulpn | grep 'PID\|user1'
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:12345 0.0.0.0:* LISTEN 1620557/sshd: user1
tcp6 0 0 :::12345 :::* LISTEN 1620557/sshd: user1
In the above example, full username is user1234
, but due to truncation, I can only read user1
.
Even more unfortunately, I learned that this truncation is hardcoded in netcat
in https://unix.stackexchange.com/questions/212096/netstat-output-line-width-limit/772314#772314 :
> Unfortunately the width of the PID/Program name column in netstat is hardcoded with [#define PROGNAME_WIDTH 20
](https://sourceforge.net/p/net-tools/code/ci/master/tree/netstat.c#l110) so there is no way of getting the full output from netstat directly. Also you end up with 19 characters and a space at the end.
The same answer also recommends:
> In today's linux one can use sudo ss -natp
to get the full info formatted a bit differently but with the full name:
... unfortunately, ss
does not print the username of the user connected to sshd
as netstat
does:
$ sudo ss -tulpn | grep user1
$
$ sudo ss -tulpn | grep 12345
tcp LISTEN 0 128 0.0.0.0:12345 0.0.0.0:* users:(("sshd",pid=1620557,fd=10))
tcp LISTEN 0 128 [::]:12345 [::]:* users:(("sshd",pid=1620557,fd=11))
So, how can I get an output identical or similar to the output of netstat -tulpn
, but which prints the full usernames connected to sshd
?
My netstat version is:
$ netstat --version
net-tools 2.10-alpha
Fred Baumgarten, Alan Cox, Bernd Eckenfels, Phil Blundell, Tuan Hoang, Brian Micek and others
+NEW_ADDRT +RTF_IRTT +RTF_REJECT +FW_MASQUERADE +I18N +SELINUX
AF: (inet) +UNIX +INET +INET6 +IPX +AX25 +NETROM +X25 +ATALK +ECONET +ROSE -BLUETOOTH
HW: +ETHER +ARC +SLIP +PPP +TUNNEL -TR +AX25 +NETROM +X25 +FR +ROSE +ASH +SIT +FDDI +HIPPI +HDLC/LAPB +EUI64
Asked by sdbbs
(578 rep)
Dec 5, 2024, 12:54 PM
Last activity: Dec 5, 2024, 01:17 PM
Last activity: Dec 5, 2024, 01:17 PM