I want to know if there is some methods to find out the current connection type to remote server (rsh or ssh?). Environment is Solaris 9, SuSE linux, csh.
How to determine current remote connection type? (rsh or ssh)
979 views Asked by Alsor Zhou At
2
There are 2 answers
0
On
Short answer : test "$SSH_CLIENT$SSH2_CLIENT$SSH_TTY"
AND who is connected AND who is your parent.
The liquidprompt project has a (bash/zsh) function to do that, which looks like :
# 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
You can use
echo $SSH_CONNECTION;
. SSH will set this environment variable on the remote server. It contains the client IP, client port, server IP, and server port. It should only be set for SSH connections.