如何确定当前的远程连接类型? (rsh或ssh)

时间:2010-08-26 02:53:51

标签: ssh csh rsh

我想知道是否有一些方法可以找到当前连接类型到远程服务器(rsh或ssh?)。环境是Solaris 9,SuSE linux,csh。

2 个答案:

答案 0 :(得分:1)

您可以使用echo $SSH_CONNECTION;。 SSH将在远程服务器上设置此环境变量。它包含客户端IP,客户端端口,服务器IP和服务器端口。它应该只为SSH连接设置。

答案 1 :(得分:0)

简短回答:测试已连接 AND 谁是您父母的"$SSH_CLIENT$SSH2_CLIENT$SSH_TTY" AND

Liquidmptmpt项目有a (bash/zsh) function来执行此操作,如下所示:

    # 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