如何判断当前远程连接类型? (rsh 或 ssh)

发布于 2024-09-16 05:02:03 字数 75 浏览 5 评论 0原文

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

皇甫轩 2024-09-23 05:02:03

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

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.

℡Ms空城旧梦 2024-09-23 05:02:03

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

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文