Category filter
Script to view Login History in macOS devices
When multiple users work on the same macOS device, it is advisable to record the history of all the users logged in to the device. This could help you in identifying the user who was using the device during a specified time. You can seamlessly fetch the login history of your macOS devices using Hexnode’s Custom Script feature.
View a brief login history
1 2 |
#!/bin/bash Who |
You will get a brief history of all the users that have logged in to your macOS device in the past few days. It returns the login time and name of the user who has logged into the device.
View a detailed login history
1 2 |
#!/bin/bash last |
You will get a detailed list of all the users that have logged in to your macOS device in the past few days. It returns the date, the login and logout time of every session, as well as the name of the user who has logged in to the device during each session.
Obtain the last logged in time of a user
If you want to check the last logged-in time of a particular user, you can use the following script.
1 2 3 |
#!/bin/sh #!/usr/bin/env bash last -1 username |
Ensure you specify the user’s name is intact. Obtain the actual username of a user using the following script:
1 2 3 |
#!/bin/sh #!/usr/bin/env bash dscl . list /Users |
It list all the users on a given machine.