Краткий ответ: тест "$SSH_CLIENT$SSH2_CLIENT$SSH_TTY"
И , кто подключен И , кто ваш родитель.
В проекте liquidprompt есть a (bash / zsh) функция , которая выглядит следующим образом:
# If this is an SSH connection.
if [[ -n "$SSH_CLIENT$SSH2_CLIENT$SSH_TTY" ]] ; then
# This is SSH.
else
# Get the host part of the who am i command.
local sess_src="$(who am i | sed -n 's/.*(\(.*\))/\1/p')"
# Get the name of the parent process.
local sess_parent="$(ps -o comm= -p $PPID 2> /dev/null)"
if [[ -z "$sess_src" && "$sess_src" = *"shepherd" ]] ; then
# This is a qrsh connection (cf. Grid Engine).
elif [[ -z "$sess_src" || "$sess_src" = ":"* ]] ; then
# This is a local connection.
elif [[ "$sess_parent" = "su" || "$sess_parent" = "sudo" ]] ; then
# This is a su/sudo
else
# This (may be) telnet.
fi
fi