Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 :-' ).

share|improve this question

3 Answers 3

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).

share|improve this answer

Try it this way:

ssh myserv users
share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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