1

The command echo "hostname" | ssh myserv returns the hostname, but echo "users" | ssh myserv does not return anything?

When I ssh on the server then run the command users, it returns my user name (since I'm connected on it :-' ).

3 Answers 3

4

users only shows users who are logged into a terminal (as recorded in utmp). echo users | ssh myserv doesn't create a terminal (it's not an interactive session), so that session isn't listed. The more common ssh myserv users similarly executes the command without creating a terminal. On the other hand, ssh -t myserv users (where -t forces a terminal to be created) should show you.

Compare also ssh -t myserv 'tty; who' (shows you logged in on that tty) with ssh myserv 'tty; who' (not a tty).

1

Try it this way:

ssh myserv users 
1

I get an error when I attempt this. Some programs require a tty. Also keep in mind that who, and users are a special case, they are looking specifically at login sessions.

# echo users | ssh host stdin: is not a tty 

See:

man sshd_config

UseLogin Specifies whether login(1) is used for interactive login sessions. The default is “no”. Note that login(1) is never used for remote command execution.

man users

users - print the user names of users currently logged in

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.