Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I run a linux file server for my office and we user SFTP for remote partners to login and download files. Is there a way to see if there are any active connections or logins so I can know when it is safe to perform maintenance on the machine?

Since the machine is almost constantly serving large files, scheduled maintenance is often bumped off due to someone either upload

share|improve this question

3 Answers 3

You could also try fuser -u ssh/tcp

share|improve this answer

You can also do:

ps -ef | grep '[s]shd' | grep -v ^root

which should show any sshd sessions (which are used for sftp). I notice on my machine my sshd process command line contains '$USER@notty' which makes sense since I'm not logged in with a terminal session. You could tighten up the grep above with:

ps -ef | grep '[s]shd:.*@notty' | grep -v ^root

BTW: the square brackets in the grep are to not have the 'grep sshd' process show up in the process list. [s]shd matches sshd, but doesn't match itself. It saves a 'grep -v grep'

share|improve this answer
2  
I ended up using netstat -atn | grep ':22' to see if there was open traffic on port 22. I also found that I could check the sshd logs, located at '/var/log/auth.log' on my system to see if all users who had opened a session had been closed out. –  jonnyflash Aug 10 '11 at 0:30

I think you can use the command line program who to see this. I have noticed some reports that doing so doesn't work, but I still think it may work (maybe it's an ssh setting).

sftp is built on top of SSH. It stands for the "SSH File Transfer Protocol". And when you're logged in over ssh, 'who' will include you as a logged in user with its output. So I'd expect this to work with active sftp sessions too.

This discussion from 2008 also suggests that you may use 'netstat' for this. It also includes a suggestion to run 'who' via 'watch' so you can see updates without doing anything.

share|improve this answer
    
who does not show users logged in via ssh(I just logged in from my laptop and checked). –  jonnyflash Aug 10 '11 at 0:27
    
That's wacky, that's GOT to be a setting.. As I'm pretty damned sure it has done so for me.. for years and years and years.. –  Doc Aug 10 '11 at 1:42
    
Any idea where that setting would be? I tried this on a public server at my work & got back what looks like realistic results with several users listed. –  jonnyflash Aug 15 '11 at 21:10

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.