0

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

4

2 回答 2

1

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

于 2010-08-26T14:56:31.190 回答
0

简短的回答:测试"$SSH_CLIENT$SSH2_CLIENT$SSH_TTY" 谁是连接的谁是你的父母。

Liquidprompt 项目有一个 (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
于 2015-04-20T09:50:50.940 回答