Is there a way to find out who is logged in to another Linux machine on the network given the machine name and not just sshing into that machine and running who? I'd prefer a way directly in python, but through a command would be fine.
|
feedback
|
migrated from stackoverflow.com Nov 5 '10 at 22:44
This question came from our site for professional and enthusiast programmers.
|
There are lots of ways of doing this (most of them insecure). Perhaps you aren't familiar with the fact that ssh can take an optional command (it logs in, runs the commands and logs out):
And if you set up a key you can do this with no password prompt. | |||
|
feedback
|
|
If the Linux machine has the
However, | |||
feedback
|
|
You could set up a service that does this for you on the remote machine and simply return the result; or you write a script that does the whole procedure for you. But I don't see why anyone outside (outside of the machine) should be able to access system information without logging in (and as soon as you log in you can use SSH instead). | |||
|
feedback
|
|
It depends, things need to be set up to allow you to do this. One possibility is 'rusers' | |||
|
feedback
|
|
If your preference is to do your ssh op's programatically via python then you should look at paramiko, a native python ssh library. There's a good over view article here Rob | |||
|
feedback
|
|
I wonder how you could discover such a thing without connecting to the machine.. You could host a small daemon on host machine which sends packets to a specified destination over time to warn about connections to itself.. but a | |||
|
feedback
|
|
Short answer: Not unless the machine is specifically set up for it. Long answer: The machine would need to be running a service on a known port that you could connect to to query this information. An alternative is to use pexpect to programmatically ssh into the machine, run | |||
|
feedback
|
|
A tricky way would be to find a way to derive the information from a directory service. Many, many people have Enterprise systems with their authorized user list/password management coming from ActiveDirectory. If you could find a way to pair your question with the Kerberos Ticket Granting Ticket service, along with short-lived tickets, it just might be possible to at least infer who is probably logged in. If the system tells the directory service when a user logs out, things are a little easier. You probably wanted the answer "finger" though and just didn't know it. Where finger went wrong though was when it started letting users create a Another interesting trick would be to have the system notify a central service whenever a user connected or disconnected. Think an IRC bot, chat server, or a REST service. Any process could periodically look for interactive sessions and submit the information in a one-way kind of fashion to an application on the other end. This application would then collate the feed to present a list of who is on "the network" to a web page. If this is for interesting business or education programs, it could be quite interesting because you could even log in users coming in through a web application like webmail. | |||
|
feedback
|
|
Only the target machine knows who's logget into it. If you cannot use SSH you'll need some other service, you can either have a server to ask to, or could have the target machine informing you via broadcast messages or something like that. | |||
feedback
|
|
You could write a daemon on the servers you want to monitor that periodically connects to a central server and sends this information to it. Perhaps via a connection to a central database over TCP then just have the daemon run "who" and upload the data via some SQL. | |||
|
feedback
|