SSH - "Last Login:" display after successful authentication - Missing

Spook

Verified User
Joined
Jan 3, 2006
Messages
138
I realize this is perhaps nothing to worry about, but I do like the idea of being able to see that the last user logged in was from a known IP. Plus I like a mystery..

I am not interested in all the alternative ways that could simulate this feature.

I've tried to cover all the details below. If anyone can offer suggestions I'd love to look into it and see if this can be figured out.

Issue:

CentOS 6 on a KVM
Code:
********************************************************************************
Authenticating with public key "root@srv2.." from agent
[root@srv2 ~]#
CentOS 6 on a OpenVZ
Code:
********************************************************************************
Authenticating with public key "admin@srv1.." from agent
Last login: Mon Mar 24 02:17:27 2014 from ..comcartel.net
[admin@srv1 ~]$
Evidence:

1. Found potential 'lastlog' related errors in log
Code:
Mar 23 11:37:37 srv2 sshd[1416]: lastlog_openseek: Couldn't stat /var/log/lastlog: No such file or directory
Mar 23 11:37:58 srv2 sshd[1413]: pam_unix(sshd:session): session closed for user root
Mar 23 23:35:51 srv2 sshd[1586]: Accepted publickey for root from me.me.me.16 port 15009 ssh2
Mar 23 23:35:51 srv2 sshd[1586]: pam_unix(sshd:session): session opened for user root by (uid=0)
Mar 23 23:35:51 srv2 sshd[1590]: lastlog_openseek: Couldn't stat /var/log/lastlog: No such file or directory
Mar 23 23:35:51 srv2 sshd[1590]: lastlog_openseek: Couldn't stat /var/log/lastlog: No such file or directory
Mar 24 00:16:13 srv2 sshd[1586]: pam_unix(sshd:session): session closed for user root
Mar 24 02:13:50 srv2 sshd[1860]: Accepted publickey for root from me.me.me.16 port 15257 ssh2
Mar 24 02:13:50 srv2 sshd[1860]: pam_unix(sshd:session): session opened for user root by (uid=0)
Mar 24 02:13:50 srv2 sshd[1863]: lastlog_openseek: Couldn't stat /var/log/lastlog: No such file or directory
Mar 24 02:13:50 srv2 sshd[1863]: lastlog_openseek: Couldn't stat /var/log/lastlog: No such file or directory
2. lastb: /var/log/btmp: No such file or directory

Steps Taken:

- compared sshd_config between systems and they're virtually the same
- created /etc/log/lastlog
- created /etc/log/btmp

touch btmp
chmod 600 btmp (to match VZ permissions)
chown root.utmp btmp (to match VZ owner.group)

touch /var/log/lastlog
chmod 644 lastlog (to match VZ permissions)
chown root.root lastlog (to match VZ owner.group)

no effect and files were not growing beyond 0 size
..btmp is for failed logins and since SSH is not 22 I guess it's possible no
ouside attempts being made. Can try making log errors myself or set back to 22.

- installed finger

lastlog grew buy running finger, however "Last login:" not being displayed after SSH login

- edit /etc/ssh/sshd_config

PrintLastLog Yes (uncomment setting & ensure set to yes)

- restart sshd

system sshd restart

Currently active /etc/ssh/sshd_config KVM ("Last login:" display not working)
Code:
#	$OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

#Port 22
Port 222
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#ListenAddress <srv2 ip>

# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile	.ssh/authorized_keys
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes

# GSSAPI options
#GSSAPIAuthentication no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing, 
# and session processing. If this is enabled, PAM authentication will 
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM no
UsePAM yes

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
PrintMotd yes
PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none

# no default banner path
#Banner none
Banner /etc/ssh.banner.txt

# override default of no subsystems
Subsystem	sftp	/usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#	X11Forwarding no
#	AllowTcpForwarding no
#	ForceCommand cvs server
AllowUsers root
#AllowUsers admin
Currently active /etc/ssh/sshd_config OpenVZ ("Last login:" displays properly)
Code:
#	$OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

#Port 22
Port 222
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#ListenAddress <srv1 ip>

# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile	.ssh/authorized_keys
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication no

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes

# GSSAPI options
#GSSAPIAuthentication no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing, 
# and session processing. If this is enabled, PAM authentication will 
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM no
UsePAM yes

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding no
#X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
PrintMotd yes
PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none

# no default banner path
#Banner none
Banner /etc/ssh.banner.txt

# override default of no subsystems
Subsystem	sftp	/usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#	X11Forwarding no
#	AllowTcpForwarding no
#	ForceCommand cvs server
AllowUsers root
AllowUsers admin
Result: no "Last login:" display after successful SSH login
 
I don't quite understand what you are trying to do or which result you are trying to reach.
Since you've put up this quote:
Authenticating with public key "admin@srv1.." from agent
Last login: Mon Mar 24 02:17:27 2014 from ..comcartel.net
[admin@srv1 ~]$
and this is your question:
but I do like the idea of being able to see that the last user logged in was from a known IP.
then the system already does what you want, doesn't it?

If you want an IP there instead of a hostname, edit /etc/ssh/sshd_config and change:
Code:
#UseDNS yes
to
Code:
UseDNS no
And restart SSH. This should give you the ip instead of the hostname.

Next to that, if you are running SSH on a port other then 22, it's possible you will get very few bruteforces on that port, because most bruteforces are against port 22.

If this is not what you mean, please clarify your exact question. Unless you mean that you want that in certain log files displayed. Maybe somebody else can help you with the log stuff.
 
Last edited:
Hi,

if you notice the "CentOS 6 on a KVM" ssh login at top does not show "Last login: xx" of anything. The OpenVZ shows something.

I am not wondering about how to change it from IP <-> name but rather why I can't get the KVM to display the information.


UPDATE: I don't yet know what the solution was in detail but JBMC visited the KVM and installed DA for me and low and behold the "Last login:" is now working. I am guessing that something in the pre-install procedure is responsible, but perhaps it's something in the broader changes that occur with the fresh DA install.

Since I may acquire another inexpensive VM just to experiment with I'm still curious to know precisely the dependencies of having the "Last login:" upon successful SSH authentication (since I probably will not use DA on an experimental VM).
 
Last edited:
I am guessing you mean PrintLastLog yes|no in the sshd_config?

I had that covered as shown in the sshd_config files above. If there is a ShowLastLogin then it must default to yes since one of my machines was showing the info... but the mystery remains, if it is part of the sshd_config directives, with a default of yes, then why both were not showing the info? :confused:
 
Ah, sorry didnt notice that :)

So before DA install LastLog wasnt show and after install it was?

Actually yes its strange.. something maybe in /etc/profile or something user-related?

Regards
 
Are you 100% sure the binaries on both systems were equal?
I know the printlastlog had some issues in earlier openssh versions and was simply not working. But that was years ago (if I remember correctly).
But you do need files like wtmp/lastlog etc for this to work. Not having these files on a working system is somewhat concerning as these files are usually deleted / altered by hackers to hide their logins.
 
@sysdev - I have no idea about the binaries being the same or not. EG: I have to refer to notes in order to do a version check like "cat /etc/redhat-release" -- however to my credit I am getting the hang of much more and frequent command and vim. :)

The KVM was/is virgin AFAIK. Honestly I wouldn't know by looking if it'd been compromised. Time from order to delivery was 10-20 mins and once I threw up the DA iptables I was surprised to see no prodding on the IP. It was only a short time (minutes) before root pw was changed and the SSH port moved. Took a few days to mess around with it, during which I noticed this 'Last Login:' trouble.

Apparently the provider CentOS configuration template (or whatever) doesn't make/require lastlog or btmp as I did need to create these manually - to no avail.

Being a KVM, once I become more confident I could investigate this from scratch again by doing a fresh installation of the OS. For the time being though, much more learning about just managing the server with SSH, Linux and DA.

I did actually do an OS reinstall and sort of panicked along the way and did a repair. In the end it booted and still had the partitions and nics operating (whew) -- Last Login: was gone again.

After the DA CB 1.2 install I did "Last Login:" was not working. However.. I did have to manually create those 2 same files (lastlog & btmp) and then it was back!

Unfortunately, although I manually did the DA pre-install steps one by one but failed to logout / in along the way checking the situation. IIRC, after all DA pre-install, but before DA install the "Last Login:" was not showing.


Summery thus far though:

Round 1

- Fresh KVM w/CentOS 6.5 - no "Last Login:" upon SSH entry
- did a bunch of stuff nothing helped (including creation of lastlog & dtmp)
- DA installed by JBMC and "Last Login:" working

Round 2

- Reinstall CentOS 6.5 from KVM panel - no "Last Login:" upon SSH entry
- yum update & DA pre-install commands - no change
- DA CB 1.2 self install - no "Last Login:"
- created missing lastlog & btmp - Success!

Between the two, rounds, there is something in the DA install that is part of the solution but also requires creating the lastlog and perhaps the btmp files.

Perhaps this is related to a somewhat faulty CentOS 6.5 image, template or whatever the provider offers.. Still a mystery to me.

Without being very observant and methodical I would need to record the process to make sure of restarting services at specific times, edits, and so forth.

Ironically, this is probably a very simple, obvious answer for experienced linux people, who would laugh at in hindsight. However the sort of quirk isolating with so many added variables distracts from the obvious.
 
Last edited:
I have this exact problem between an OpenVZ and KVM Virtual hosts running debian.
 
Back
Top