Purchase Linux CDs / DVDs / Flash Drives at OSDisc.com

Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd, 2017 please sign up again. Thanks!

  1. Follow us on twitter - we shoot all of our new original content out as well as random messages. https://twitter.com/linuxdotorg
    Dismiss Notice

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

Discussion in 'Command Line' started by AntiRix, Mar 15, 2019.

  1. AntiRix

    AntiRix New Member

    Joined:
    Mar 13, 2019
    Messages:
    7
    Likes Received:
    2
    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.


    (Log in to hide this advertisement)


    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.
     
    #1 AntiRix, Mar 15, 2019
    Last edited: Mar 15, 2019

Share This Page