Leaving incrond for systemd.path

I’ve been having problems with incrond for months; after trying to upgrade from version 0.5.10, incrond would not trigger after a specified event occurred in the monitored path.

After upgrading to version 0.5.12-9 (I couldn’t use 0.5.10 because of security policies), incrond has started behaving in a completely random way: sometimes it was triggered as expected but some other times (way too many), nothing was happening.

This was the entry in incrontab:

/home/elena/upload IN_CLOSE_WRITE /bin/find $@ -type f -exec /bin/chmod g+rw {} \+

Writing a script and adding it to crontab was out of question; here is where systemd came in handy, with path units.

A .path unit (systemd.path) monitors a file or directory and it calls a .service unit (systemd.service), usually with the same name, when something happens to the monitored file or directory.Continue reading

AWK basics

Printing columns

Print all the columns:

$ awk '{print $0}' FILE

Print the 1 column:

$ awk '{print $1}' FILE

Print the last column:

$ awk '{print $NF}' FILE

Print multiple columns:

$ awk '{print $1 $3}' FILE

Specifying field separator

By default, awk uses space and tab as field separator. You can specify how fields are separated using the -F option.

$ awk -F "/" '{print $1}' FILE

Excluding columns

Print all the columns but not the 2 one:

$ awk '{$2=""; print $0}' FILE

Print all the columns but not 1 and 2:

$ awk '{$1=$2=""; print $0}' FILE

 

SSH: No supported key exchange algorithms [preauth]

I’ve recently installed Solaris 11.4 on a VM and, as soon as I tried to log in remotely using SSH, my connection was refused straight away. First of all, I checked if the service was enabled:

$ svcs ssh
STATE          STIME    FMRI
online         13:23:15 svc:/network/ssh:default

I checked SSH directory under /etc and something was definitely not quite right with the auto-generated keys:

-rw-------   1 root     root         0 Jan  4 13:23 ssh_host_ed25519_key
-rw-r--r--   1 root     root         0 Jan  4 13:23 ssh_host_ed25519_key.pub
-rw-------   1 root     root         0 Jan  4 13:23 ssh_host_rsa_key
-rw-r--r--   1 root     root         0 Jan  4 13:23 ssh_host_rsa_key.pub

The keys were there… but truncated to zero.

Something, somewhere went wrong during the key generation (usually when OpenSSH is run for the first time) so I deleted the keys and restarted the service:

# svcadm restart ssh

The keys were re-generated and I was able to log in.

View a certificate fingerprint

It’s possible to check a certificate fingerprint using openssl:

  • SHA-1
openssl x509 -noout -fingerprint -sha1 -inform pem -in [cert-file]
  • SHA-256
openssl x509 -noout -fingerprint -sha256 -inform pem -in [cert-file]
  • MD5
openssl x509 -noout -fingerprint -md5 -inform pem -in [cert-file]

Iptables: block all traffic except SSH

I needed to update some servers and block traffic generated by a lot of services. Since I couldn’t block every single service neither disconnect the network, I used this simple iptables rule:

iptables -A INPUT -p tcp -m state --state NEW -m multiport ! --dports 22 -j REJECT