开发者

How to determine current remote connection type? (rsh or ssh)

I want to know if there is some methods to find out the current connection type to remote server (rsh or ssh开发者_如何学Go?). Environment is Solaris 9, SuSE linux, csh.


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜