I am exploring methods to correlate my current SSH session with the SSHD logs.
I aim to extract specific information from the SSHD logs that pertain to my SSH session only.
Jul 04 09:39:06 linuxbox sshd[1122]: Accepted publickey for testuser from 1.2.3.4 port 123 ssh2: RSA-CERT ID test (serial 1) CA RSA fingerprint...
One option was to map the sshd pid logged during ssh login sshd[1122] to the current ssh session pid. But I could not find a way to get current ssh session pid.
Or Is there any other way to map my session to the sshd logs apart from matching PID?
testuser@linuxbox:~$
testuser@linuxbox:~$ sudo systemctl status sshd
* ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2023-07-04 09:10:20 UTC; 29min ago
Docs: man:sshd(8)
man:sshd_config(5)
Process: 1023 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 1024 (sshd)
Tasks: 1 (limit: 1109)
Memory: 2.7M
CGroup: /system.slice/ssh.service
`-1024 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
Jul 04 09:39:03 linuxbox sshd[1122]: rexec line 126: Deprecated option UsePrivilegeSeparation
Jul 04 09:39:06 linuxbox sshd[1122]: Accepted publickey for testuser from 1.2.3.4 port 123 ssh2: RSA-CERT ID test (serial 1) CA RSA fingerprint...
Jul 04 09:39:06 linuxbox sshd[1122]: pam_unix(sshd:session): session opened for user testuser by (uid=0)
testuser@linuxbox:~$ date
Tue 04 Jul 2023 09:39:50 AM UTC
testuser@linuxbox:~$ ps -ef | grep sshd
root 881 1 0 09:05 ? 00:00:00 sshd: testuser [priv]
root 884 1 0 09:05 ? 00:00:00 sshd: testuser [priv]
testuser 893 881 0 09:05 ? 00:00:00 sshd: testuser@pts/0
testuser 904 884 0 09:05 ? 00:00:00 sshd: testuser@notty
root 1024 1 0 09:10 ? 00:00:00 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
root 1122 1024 0 09:39 ? 00:00:00 sshd: testuser [priv]
testuser 1124 1122 0 09:39 ? 00:00:00 sshd: testuser@pts/1
testuser 1151 1125 0 09:39 pts/1 00:00:00 grep --color=auto sshd
testuser@linuxbox:~$