How to get list of users connected to file sharing

file-sharingserver.appsharing

My desktop Mac mini (2018) shares files to other computers on the network. I've set it up in System Preferences > Sharing so that only known users can connect, with their username and password.

If I go to restart my Mini, I sometimes get a message to say that 1 or more users are connected.

Is there an easy way to find out which users are connected?

I used to use Server.app, and it would be easy to use that (or serveradmin on the CLI) to determine who was logged in. But since Server has been 'withdrawn', it doesn't seem so easy. I'm on Mojave.

last |grep "logged in" gives:

Ben       ttys000                   Sun Jun  7 15:24   still logged in
Ben       console                   Sun Jun  7 15:22   still logged in

which doesn't seem to include current AFP connected users, as suggested by the recommended article. Nor does it give those connected to TM sharing or other connections; however, those can be gleaned from Activity Monitor.

netstat -na |grep 139

just gives me a bunch of IP6 addresses.

tcp6       0      0  fe80::18cf:f908:.51390 fe80::cab:3d08:d.61984 ESTABLISHED
tcp6       0      0  fe80::18cf:f908:.61391 fe80::cab:3d08:d.61898 CLOSE_WAIT 
tcp6       0      0  fe80::18cf:f908:.54029 fe80::cab:3d08:d.61394 CLOSE_WAIT 
tcp6       0      0  fe80::18cf:f908:.64954 fe80::cab:3d08:d.56139 CLOSE_WAIT 
tcp6       0      0  fe80::18cf:f908:.50799 fe80::cab:3d08:d.51394 CLOSE_WAIT 
tcp6       0      0  fe80::18cf:f908:.52279 fe80::cab:3d08:d.61394 CLOSE_WAIT 
6f249e60a5b12c27 stream      0      0                0 6f249e60a5b1396f                0                0
6f249e60a5b1396f stream      0      0                0 6f249e60a5b12c27                0                0

The best I've found is:

netstat -f inet -n | grep '.548 ' | awk '{ print $5 }' | sed 's/\.[^.]*$//'

which gives me IP4 addresses for all connections except SMB.

Ideally, something that lists the connection type and username would be ideal, but it does seem that this is going to require a script rather than a one-liner.

Best Answer

You can open Activity Monitor and the right-most column of the displayed data is Users. Click on users to sort the data by user. You can then see who all is on the computer. This method was explained in the OSX Daily article found here.