LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-11-2017, 06:43 PM   #1
luofeiyu
Member
 
Registered: Aug 2015
Posts: 237

Rep: Reputation: Disabled
How to get the seccessful ssh connection log info ?


OS: centos7.
Code:
cat /var/log/secure
Nov 11 19:34:03 myvps sshd[9230]: Failed password for root from 59.63.188.36 port 55281 ssh2
Nov 11 19:34:03 myvps sshd[9230]: Received disconnect from 59.63.188.36: 11:  [preauth]
Nov 11 19:34:03 myvps sshd[9230]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=59.63.188.36  user=root
Nov 11 19:34:42 myvps sshd[9234]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=59.63.188.36  user=root
Nov 11 19:34:44 myvps sshd[9234]: Failed password for root from 59.63.188.36 port 46377 ssh2
Nov 11 19:34:46 myvps sshd[9234]: Failed password for root from 59.63.188.36 port 46377 ssh2
Nov 11 19:34:48 myvps sshd[9234]: Failed password for root from 59.63.188.36 port 46377 ssh2
Nov 11 19:34:48 myvps sshd[9234]: Received disconnect from 59.63.188.36: 11:  [preauth]
Nov 11 19:34:48 myvps sshd[9234]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=59.63.188.36  user=root
Nov 11 19:35:30 myvps sshd[10244]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0
ALL of them are failed connection , no successful connection.

No info on the coommand.
Code:
cat /var/log/secure   |grep  succ
How to get the seccessful ssh connection log info ?
 
Old 11-11-2017, 07:47 PM   #2
luofeiyu
Member
 
Registered: Aug 2015
Posts: 237

Original Poster
Rep: Reputation: Disabled
cat /var/log/secure |grep Accepted
 
Old 11-12-2017, 01:02 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,366
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
Or you could write a more concise variant by avoiding the cat, which is not necessary:

Code:
grep Accepted /var/log/secure
Another option, if there are a lot of other non-SSH related log entries would be to use AWK to guarantee that "Accepted" lines are only shown for SSH:

Code:
awk '$5~/sshd/ && $6="Accepted"' /var/log/secure
The $5 and $6 refer to the fifth and sixth fields respectively. The ~// binds the pattern search to the preceding field, which in that case is the fifth.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to log ssh activity in /var/log/ssh/ssh*.log MrUmunhum Linux - Server 3 11-02-2011 02:25 AM
[SOLVED] How to check log files for ssh connection attempts Dave_P Linux - Security 18 10-06-2011 04:09 PM
Log commnds in SSH connection YaaY Linux - Security 9 05-10-2011 01:39 AM
Bash Script to log off of ssh connection Betzie Programming 4 07-07-2009 04:29 PM
How to get SSH connection info programatically? Murali Mohan Linux - Networking 5 05-19-2006 03:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration