Skip to Content
+1 (888) 578-8743[email protected]
Ringing Liberty

Ringing Liberty

Freedom through Communications

Home Operations Operations Find out how long a user was logged into a Linux server

Find out how long a user was logged into a Linux server

on January 30, 2013January 30, 2013by

andreas-h asked:

In my Debian Squeeze server, all user logins and logouts are recorded in the file /var/log/auth.log

Jan 28 07:11:06 xen8 sshd[29826]: pam_unix(sshd:session): session opened for user root by (uid=0)
Jan 28 07:33:47 xen8 sshd[29826]: pam_unix(sshd:session): session closed for user root
Jan 28 09:45:58 xen8 sshd[14374]: pam_unix(sshd:session): session opened for user root by (uid=0)
Jan 28 09:47:36 xen8 sshd[14374]: pam_unix(sshd:session): session closed for user root
Jan 29 07:37:48 xen8 sshd[24940]: pam_unix(sshd:session): session opened for user root by (uid=0)
Jan 29 07:38:11 xen8 sshd[24940]: pam_unix(sshd:session): session closed for user root
Jan 29 08:35:13 xen8 sshd[25707]: pam_unix(sshd:session): session opened for user root by (uid=0)
Jan 29 08:37:06 xen8 sshd[25707]: pam_unix(sshd:session): session closed for user root
Jan 29 16:59:39 xen8 sshd[30725]: pam_unix(sshd:session): session opened for user root by (uid=0)
Jan 29 17:00:58 xen8 sshd[30725]: pam_unix(sshd:session): session closed for user root
Jan 29 17:11:17 xen8 sshd[30832]: pam_unix(sshd:session): session opened for user root by (uid=0)
Jan 29 18:11:37 xen8 sshd[30832]: pam_unix(sshd:session): session closed for user root

Via the process id, one should be able to find matching logins/logouts, and then one could calculate the time. But my sed/awk skills are very limited, and maybe there’s even a ready-made script/tool for this task out there?
Is there an easy way to extract the times a user was logged in? Either in a total (per file), or maybe even with some nice graphics?

My answer:


Try the last command. This should show you all the information you’re looking for.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

accountinglog-filesloginsyslog

Post Navigation

restrict root access for certain files or filesystems
unable to restore mysql database, getting ERROR 1153 (08S01)

Related Post

Virtual firewall to protect hypervisor

redirect to url only if the destination url is valid

Ubuntu 18.04: Communication to server on localhost stops working after setting a port forwarding rule

Problems with vfs.file.exists on Zabbix 2.0

Can not update Bash on Debian 6.0 (Squeeze)

What cable do I require for SFF-8087 to SAS

Latest Posts

  • CentOS yum-cron updates stability
  • Best solutions for auto deployment of multiple server applications
  • Does the OS stop all PIDs before restarted when the user clicks restart in Ubuntu?
  • How to get the remote hostname resolved through DNS when using Nginx and ModSecurity?
  • tcpdump output has a different hostname

Recent Comments

  • kg on Matching autonomous system numbers in iptables
  • Alex on Matching autonomous system numbers in iptables
  • How do I get puppet master to listen on IPv6? - Ringing Liberty on Making Puppet Enterprise 3.7 work with IPv6
  • Dan on Matching autonomous system numbers in iptables
  • JohnnyB on Making Puppet Enterprise 3.7 work with IPv6

Tags

amazon-ec2 amazon-web-services ansible apache-2.2 apache-2.4 bash cache centos centos6 centos7 configuration debian docker domain-name-system email email-server fedora firewall iptables ipv6 kvm-virtualization linux linux-networking mysql networking nginx php php-fpm postfix redhat redirect reverse-proxy rpm security selinux smtp ssh ssl systemd ubuntu virtual-machines virtualization windows wordpress yum

About Ringing Liberty

Ringing Liberty is the personal web site of Michael Hampton, a professional system administrator.

Email: [email protected]
Phone: +1 888 578-8743

© Copyright 2022 Ringing Liberty. All Rights Reserved. Blossom Consulting | Developed By Blossom Themes. Powered by WordPress.Privacy Policy