2

Hey forum!

I have recently begun working with Debian and do so in a purely command-line environment. I connect from a windows desktop through puTTY using asymmetric encryption rather than passwords.

My principle reason for running a Linux server is to allow SFTP access to share files with external users over the internet. I do this using SSH and a 'chroot jail' which gives me a reasonable degree of inherent security. Nonetheless I need to be fairly diligent in examining the '/var/logs/auth.log' file for intrusion attempts. Unfortunately I have discovered this holds authentication data for all logins in the Linux system, not just the SSH daemon - which is quite hard to run my eyes over!

In order to narrow the log entries displayed to just those relevant for SFTP reporting I currently use:

grep SSHD /var/logs/auth.log | more

However, I wondered if there was an alternative to 'more' that I could pipe 'grep's output into that would offer colourization similar to 'vim/view' with ':syntax enable' set?

The closest I have come so far is:

grep --color=always SSHD /var/logs/auth.logs | more

This gives a red 'SSHD' highlighting in the text string which does indeed help the eyes a little. However it is not so good as the syntax highlighting in 'vim'.

1 Answer 1

1

If you don't mind installing external tools, my call would be Pygments

It is a generic syntax highlighter for general use in all kinds of software such as forum systems, wikis or other applications that need to prettify source code. Highlights are:

  • a wide range of common languages and markup formats is supported
  • special attention is paid to details that increase highlighting
  • quality support for new languages and formats are added easily; most languages use a simple regex-based lexing mechanism
  • a number of output formats is available, among them HTML, RTF, LaTeX and ANSI sequences
  • it is usable as a command-line tool and as a library ...
  • and it highlights even Brainf*ck!

After installing it, you can use it like:

pygmentize -g file

... and you will get a beautiful colorized output.


You can even use it as an alias - put this in your .profile file:

alias colorseverywhere='pygmentize -g'

... and then try running it like (as per your example):

grep SSHD /var/logs/auth.log | colorseverywhere

... or just:

colorseverywhere /var/logs/auth.log

I hope this helps!

1
  • Many thanks Jim - I will give that a look over! I like the fact it can be used with many different input files.
    – user342650
    Jul 9, 2014 at 15:39

You must log in to answer this question.