Answers:
从ssh
手册页:
SSH_CONNECTION
Identifies the client and server ends of the connection.
The variable contains four space-separated values: client IP address,
client port number, server IP address, and server port number.
....
SSH_TTY
This is set to the name of the tty (path to the device) associated
with the current shell or command. If the current session has no tty,
this variable is not set.
因为您不在ssh会话中,所以未设置这些变量。
man bash
并搜索这些变量的含义。无论您是否处于ssh会话中,它们始终被设置。
正如其他人所提到的,这些变量仅在进行会话时设置。要亲自查看,请在活动的SSH会话下检查值:
ssh user@host 'echo SSH_TTY: $SSH_TTY SSH_CONNECTION: $SSH_CONNECTION'