Retrieving a unique identifier for both SSH and directly-connected sessions

AntiRix

New Member
Joined
Mar 13, 2019
Messages
10
Reaction score
2
Credits
0
Hi,

I'm trying to keep a log of the IP addresses used to log into my Raspberry Pi, both with a direct connection and through SSH, which I've managed to do. However, it's possible to have multiple SSH windows open from the same IP address, and I want to be able to distinguish between the sessions. By 'directly-connected', I mean the keyboard is plugged directly into the Pi.

In ~/.bashrc, used for tracking logins, I'm able to use $(tty) to get something in the format '/dev/pts/X'. In ~/.profile, I have:

Code:
trap '$HOME/.logout' 0

In ~/.logout, $(tty) returns 'not a tty' rather than the same value it returns on login, in ~/.bashrc. This must be because its value is undefined at the point of logout. Is there any way to get any form of unique identifier for both SSH and direct sessions, which can be retrieved in ~/.bashrc and ~/.logout?

I'm also happy to have a system which creates a file which only that session can access, used to store a generated ID, if this is possible.
 
Last edited:

Members online


Latest posts

Top