From ab8ce23ef342a7df81ac8fd6d74d113894d4dcb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Mass=C3=A9?= Date: Tue, 23 Apr 2019 11:13:57 +0200 Subject: [PATCH] 2019-04-23 update --- .../print-config-file-without-comments.md | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 content/blog/print-config-file-without-comments.md diff --git a/content/blog/print-config-file-without-comments.md b/content/blog/print-config-file-without-comments.md new file mode 100644 index 0000000..609a8a3 --- /dev/null +++ b/content/blog/print-config-file-without-comments.md @@ -0,0 +1,47 @@ +--- +title: "Bash Snippet: Print a config file without comments" +date: 2019-04-23T00:00:00+02:00 +--- + +Logging in on a server, printing a configuration file and trying to find the relevant setting from thousands of comment lines. +Sounds familiar? + +Not that comments are useless in a configuration file but sometimes it's handy to print a configuration file without the comment lines. +Especially when the file is thousand lines long but the useful lines fit the twenty five lines of a standard terminal. + +The `egrep` command which is standard on most Linux distributions and on MacOS, can strip out the unwanted lines: + +```sh +egrep -v '^\s*(#|$)' /etc/ssh/sshd_config +``` + +The `-v` switch prints out the lines that **do not** match the given regex `^\s*(#|$)`. +And this regex captures: + +- empty lines +- lines with only whitespaces +- lines that contains only comments + +And now, your active sshd configuration fits a 25 lines terminal! + +```raw +$ egrep -v '^\s*(#|$)' /etc/ssh/sshd_config +HostKey /etc/ssh/ssh_host_rsa_key +HostKey /etc/ssh/ssh_host_ecdsa_key +HostKey /etc/ssh/ssh_host_ed25519_key +SyslogFacility AUTHPRIV +PermitRootLogin no +AuthorizedKeysFile .ssh/authorized_keys +PasswordAuthentication no +ChallengeResponseAuthentication no +GSSAPIAuthentication yes +GSSAPICleanupCredentials no +UsePAM yes +X11Forwarding yes +UseDNS no +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 +Subsystem sftp /usr/libexec/openssh/sftp-server +```