How to figure out if my login is on serial console in busybox ash?

Hey everyone!

I want to put a block of code in my ~/.profile to run only when I have logged in via the serial console. I never want it to run when I log in via telnet/ssh/whatever.

My system has "::askconsole:/bin/login" set in /etc/inittab, so console access is authenticated, but I don't think this should really matter.

I immediately thought about using the "tty" command to print the tty I'm logged in on, but I have multiple device types I would like to use this on, and they don't all use the same dev name for the tty.

Any bright ideas?

set
[ -z "$SSH_TTY" ] && echo NOT_SSH

I thought about using something like an SSH_ env var, but that's proving a negative instead of the positive.

Thanks for the idea though

on second thought, the tty command isn't even in the default build config, so that's probably not going to work for me. May have to go with SSH_ env after all, unless I can find something better.

Works for me:

mkdir -p /etc/profile.d
echo '[ -n "$SSH_TTY" ] && echo SSH_DETECTED || echo NO_SSH_DETECTED' > /etc/profile.d/ssh.sh

2 posts were split to a new topic: Deny login via serial console