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


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


Try it this way:

ssh myserv users

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


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

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.