17

What are the SSH_TTY and SSH_CONNECTION variables for? On my Ubuntu system both of them are blank; what values should they have?

4 Answers 4

16

From ssh man page:

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.

Because you are not in a ssh session, so these variables are not set.

2
  • I get it now , so what is the meaning of SHELL and HOSTNAME variables too ? Mar 17, 2014 at 17:14
  • 2
    You can type man bash and search for those variables's meaning. They are always set, regardless of you are in ssh session or not.
    – cuonglm
    Mar 17, 2014 at 17:28
2

Both variables are only defined when you are logged in through ssh. SSH_TTY specifies the device node of the current virtual terminal (e.g. /dev/pts/25). The SSH_CONNECTION is set to ip and port on client and on host machine (4 fields separated by whitespace).

2

As mentioned by others, these variables are only set when a session is made. To see this for yourself, inspect the values under an active SSH session:

ssh user@host 'echo SSH_TTY: $SSH_TTY SSH_CONNECTION: $SSH_CONNECTION'
2

Upon a successful connection, OpenSSH sets several environment variables.

SSH_CONNECTION shows the address of the client, the outgoing port on the client, the address of the server and the incoming port on the server.

SSH_TTY names the pseudo-terminal device, abbreviated Ppty, on the server used by the connection.

For example:

SSH_CONNECTION='192.168.223.17 36673 192.168.223.229 22'
SSH_TTY=/dev/pts/6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.