LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-14-2020, 12:08 PM   #1
pete.g
LQ Newbie
 
Registered: Jun 2020
Posts: 9

Rep: Reputation: Disabled
How to send SSH logs to a text file?


How do I get the debug logs you get when using the "-vvv" switch with the ssh command "ssh -vvv username@remotehost" redirected to a text file rather than the users screen?

It's very distracting for the user to get all that extra output popping up on their screen whenever using ssh.

I'd like this to be totally transparent to the user, and not asking them to do anything different than what they usually do.

I've tried adding the DEBUG line to ssh_config, but it clutters up their screen with log messages - it doesn't pipe anything to a file.

This is using CentOS 7.7.

Thanks

Last edited by pete.g; 07-14-2020 at 12:13 PM.
 
Old 07-14-2020, 12:28 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
From man ssh
Code:
-y      Send log information using the syslog(3) system module.  By default this information is sent to stderr.
This implies that you could redirect STDERR to a file, but you'd need to confirm that.

Are you having the users enter the -vvv? Then you'd need to add the -y
Code:
ssh -yvvv username@remotehost
or the redirect
Code:
ssh -vvv username@remotehost 2> /path/to/somefile
Insure that the user has write permission to the location of somefile.

If you're using a script or an alias to add the debug option, you can just adjust it, of course.

Last edited by scasey; 07-14-2020 at 12:29 PM.
 
Old 07-14-2020, 12:31 PM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Or even save directly to the log file without a redirect.

Code:
ssh -E ~/ssh.log -vvv you@remote
Dig around in the manual page, since there will be other options worth knowing about. You won't remmeber all of them but you might remember that they're there and benefit from being able to look them up.
 
1 members found this post helpful.
Old 07-14-2020, 12:35 PM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Also this from man ssh_config:
Code:
    LogLevel
             Gives the verbosity level that is used when logging messages from ssh(1).  The possible values are: QUIET, FATAL, ERROR, 
             INFO, VERBOSE, DEBUG, DEBUG1, DEBUG2, and DEBUG3.  The default is INFO.  DEBUG and DEBUG1 are
             equivalent.  DEBUG2 and DEBUG3 each specify higher levels of verbose output.
Don't know if that will suppress the output to the screen, tho.

So, as suggested, dig around in the man pages more.
 
Old 07-14-2020, 12:37 PM   #5
pete.g
LQ Newbie
 
Registered: Jun 2020
Posts: 9

Original Poster
Rep: Reputation: Disabled
As I stated I don't want the users to have to do anything on their end - they shouldn't have to add any switches to their command line for this to happen.

I'm assuming this can be configured to happen in a .conf file somewhere.
 
Old 07-14-2020, 12:39 PM   #6
pete.g
LQ Newbie
 
Registered: Jun 2020
Posts: 9

Original Poster
Rep: Reputation: Disabled
The LOGLEVEL option in ssh_config sends all messages to the users screen - I don't want it sent to their screen - I want it sent to a log file, without the user having to add any switches to their commandline
 
Old 07-14-2020, 12:43 PM   #7
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by pete.g View Post
The LOGLEVEL option in ssh_config sends all messages to the users screen - I don't want it sent to their screen - I want it sent to a log file, without the user having to add any switches to their commandline
Study man ssh_config then. If it can be done from the command line, it can probably be done from the config file. Look for something similar to the -E option in man ssh.
 
1 members found this post helpful.
Old 07-14-2020, 12:51 PM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,841

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you can use an alias for ssh (or users can have their own personal aliases)
 
2 members found this post helpful.
Old 07-14-2020, 12:52 PM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by pete.g View Post
As I stated I don't want the users to have to do anything on their end - they shouldn't have to add any switches to their command line for this to happen.
Confused by this; you say you don't want them to have any switches added to their command line...yet say they're starting things with "-vvv"??? You also say it's distracting for the user, but what actual PROBLEM does it cause, and why enable the -vvv to start with, if you don't want/need that diagnostic info? Typically that flag is done to diagnose connectivity problems, not for daily use.
Quote:
I'm assuming this can be configured to happen in a .conf file somewhere.
Not that I can see. However, since you're ALREADY specifying the "-vvv" on the command line, specify something else:
Code:
ssh user@10.11.12.13 -vvv 2>/var/log/username-ssh-info.log
..which will redirect the diagnostic messages to that file. Simple enough to write a bash script 'wrapper' to take a user name and IP address, and run the command line like that for all users.
 
Old 07-14-2020, 12:55 PM   #10
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Most of the options which you can add at run time can be included in a configuration file for the client. However, -E is not one of them, it appears. See "man ssh_config". You could grab the output using LogLevel and SyslogFacility via the system logs, as mentioned above.

There are user-level client configuration files, defaulting to ~/.ssh/config, and system-wide client configuration files, defaulting to /etc/ssh/ssh_config and /etc/ssh/ssh_config.d/* and the former override the latter if they exist.

Code:
Host *.example.com
       LogLevel DEBUG3
       SyslogFacility LOCAL0
Also the contents of the file should go from specific to general since they configuration options are applied on the first use basis.
 
3 members found this post helpful.
Old 07-14-2020, 01:15 PM   #11
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by Turbocapitalist View Post
Most of the options which you can add at run time can be included in a configuration file for the client. However, -E is not one of them, it appears. See "man ssh_config". You could grab the output using LogLevel and SyslogFacility via the system logs, as mentioned above.

There are user-level client configuration files, defaulting to ~/.ssh/config, and system-wide client configuration files, defaulting to /etc/ssh/ssh_config and /etc/ssh/ssh_config.d/* and the former override the latter if they exist.

Code:
Host *.example.com
       LogLevel DEBUG3
       SyslogFacility LOCAL0
Also the contents of the file should go from specific to general since they configuration options are applied on the first use basis.
That worked for me, except I don't know where the log file ended up.
I put that in the user's ~/.ssh/ssh_config (not ~/.ssh/config on my CentOS 7 box) Hmm. the man page does say .ssh/config, but .ssh/ssh_config seems to work.

Edit: Hmm. I don't find a SysLogFacility option in the ssh_config man page here...I'm not finding anything to specify a log file for the ssh client - except the -E command line option.

Last edited by scasey; 07-14-2020 at 01:22 PM.
 
Old 07-14-2020, 01:20 PM   #12
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
That would be as defined in your /etc/rsyslog.conf

local7.* /var/log/boot.log
 
1 members found this post helpful.
Old 07-14-2020, 01:28 PM   #13
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Turbocapitalist View Post
Most of the options which you can add at run time can be included in a configuration file for the client. However, -E is not one of them, it appears. See "man ssh_config". You could grab the output using LogLevel and SyslogFacility via the system logs, as mentioned above.

There are user-level client configuration files, defaulting to ~/.ssh/config, and system-wide client configuration files, defaulting to /etc/ssh/ssh_config and /etc/ssh/ssh_config.d/* and the former override the latter if they exist.
Code:
Host *.example.com
       LogLevel DEBUG3
       SyslogFacility LOCAL0
Also the contents of the file should go from specific to general since they configuration options are applied on the first use basis.
Nice one.
 
Old 07-14-2020, 01:33 PM   #14
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by michaelk View Post
That would be as defined in your /etc/rsyslog.conf

local7.* /var/log/boot.log
Aha. Learn something every day! Thanks! No local0 there, but I suppose one could be added to log ssh stuff...or some other rule.
I'll leave that to the OP to figure out.

Another idea that comes to mind is to alias ssh to include the -E option...oh...already suggested by pan64.

All in all an interesting problem...and I think the solution is here. pete.g, please let us know which idea worked out for you.

Last edited by scasey; 07-14-2020 at 01:35 PM.
 
Old 07-14-2020, 02:45 PM   #15
pete.g
LQ Newbie
 
Registered: Jun 2020
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thumbs down

Quote:
Originally Posted by Turbocapitalist View Post
Most of the options which you can add at run time can be included in a configuration file for the client. However, -E is not one of them, it appears. See "man ssh_config". You could grab the output using LogLevel and SyslogFacility via the system logs, as mentioned above.

There are user-level client configuration files, defaulting to ~/.ssh/config, and system-wide client configuration files, defaulting to /etc/ssh/ssh_config and /etc/ssh/ssh_config.d/* and the former override the latter if they exist.

Code:
Host *.example.com
       LogLevel DEBUG3
       SyslogFacility LOCAL0
Also the contents of the file should go from specific to general since they configuration options are applied on the first use basis.
------------
That was along the lines of what I was looking for, but it's not quite working yet:

When I try to ssh anywhere after adding this snippet to /etc/ssh/ssh_config, I get an error "Bad configuration option: syslogfacility"
If I add it to .ssh/config, I get an error "bad owner or permissions on /home/user/.ssh/config" even if I make the permissions 777
I added a line to /etc/rsyslog.conf "local0.* /var/log/ssh.log".
For testing purposes I made that log with 777 permissions too.

Last edited by pete.g; 07-14-2020 at 03:13 PM.
 
  


Reply

Tags
ssh



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
Back up logs file and create a script showing the backed up logs and the running logs Billy_6052 Programming 5 12-13-2014 02:32 AM
Enable Audit logs to send logs to syslog-ng (remote server) Iyyappan Linux - Server 5 01-07-2014 04:15 PM
How to send my all logs from ubuntu send email to me DeSouffle Linux - Networking 1 12-21-2013 04:15 AM
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 02:36 PM
Postfix : mail cannot send to send outside ( can send/receive locally) bobbinsupport Linux - Networking 3 12-15-2007 10:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:01 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