Sample Header Ad - 728x90

How can root get access to SSH_TTY

0 votes
1 answer
162 views
I *think* that SSH_TTY is an environment variable set by ssh that holds the device node of the current virtual terminal; e.g. /dev/pts/0, /dev/pts/1 , etc. I know that when I'm logged in to an SSH server, I can see the device node assigned to each session by simply entering echo $SSH_TTY. And I can see *all* device nodes in use (at least under my username) by entering w or who from the terminal. I can use the value of $SSH_TTY in a script in ~/.profile (or ~/.bash-profile) to (e.g.) make decisions about which directory to open for each session. IOW, SSH_TTY has an assigned value by the time my login has progressed to reading ~/.profile. I'd also like to communicate the value of SSH_TTY to the user in the MOTD, but am currently unable to do this. I *think* this is because root runs all the scripts in /etc/update-motd.d at login, and root has no SSH_TTY. And so I've looked for a *work-around*. The only one I've found is this:
#!/usr/bin/sh
su pi -c echo "Greetings, I see you rode in on $SSH_TTY"
But this fails silently. How can I do this?
Asked by Seamus (3772 rep)
Feb 17, 2024, 08:22 AM
Last activity: Feb 28, 2024, 04:06 PM