Slackware Kernel Upgrade (elilo)
If you are using elilo with Slackware, after running the slackpkg --upgrade-all script and you see that a new kernel was installed, you need to run the following commands to move the latest kernel to its proper location in order to boot:
geninitrdcp /boot/vmlinuz-generic /boot/efi/EFI/Slackware/vmlinuzcp /boot/initrd.gz /boot/efi/EFI/Slackware/initrd.gz
How to Change the UID or GID for a User or Group
Let’s assume we have a user, Jane Doe, with the username of jdoe and the UID of 1001 who we need to move to another UID (for some reason or another).
First, change the UID of the user:
# usermod -u 3001 jdoe
Next, use search and change all file’s ownership owned by this user:
# find / -user 1001 -exec chown -h jdoe {} \;
Netstat
My most frequently used netstat command with parameters for checking port (active internet) connections is:
$ netstat -tulpn
You can also pipe the output to grep to filter for specific ports or addresses.
Here is a brief listing of some of the many options:
$ netstat [options]
| Option | Action |
|---|---|
| -a | Display the state of all sockets, not just the active. |
| -c | Continuously display information, updating every second. |
| -i | Include network device statistics. |
| -n | Display all network addresses as numbers. |
| -o | Display additional information. |
| -r | Display routing tables. |
| -t | Display only the TCP sockets. |
| -u | Display only the UDP sockets. |
| -v | Print the netstat version number and exit. |
| -w | List only the raw sockets. |
| -x | Display only the Unix sockets. |
Extracting Client Certificates
You can display all of the server’s certificates using the following command:
$ openssl s_client -showcerts server.name:port | sed -n '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p'
This output can be piped or copy/pasted to a text file (only keep the parts between the BEGIN and END CERTIFICATE sections) and give it a .crt file extension. You can then use it as input to whatever client app needs it.
In the below example we pipe the openssl output to grep to remove the identifiers of the certificates. You may not get your prompt back until the command times out, so you should wait a bit and after a bit you should get something similar to the following output:
Use the zdump Command to Check Daylight Savings Time Settings
If you are one of us lucky folks who live in timezones that observe Daylight Savings Time, you can use the zdump timezone dumper command to view your server’s settings for same. This command prints the current time in each timezone provided on the command line.
You can use grep to reduce the output to just the lines that reference the current year:
$ zdump -v EST5EDT |grep '2023'EST5EDT Sun Mar 12 06:59:59 2023 UT = Sun Mar 12 01:59:59 2023 EST isdst=0 gmtoff=-18000EST5EDT Sun Mar 12 07:00:00 2023 UT = Sun Mar 12 03:00:00 2023 EDT isdst=1 gmtoff=-14400EST5EDT Sun Nov 5 05:59:59 2023 UT = Sun Nov 5 01:59:59 2023 EDT isdst=1 gmtoff=-14400EST5EDT Sun Nov 5 06:00:00 2023 UT = Sun Nov 5 01:00:00 2023 EST isdst=0 gmtoff=-18000
Logging to the System Logger in Bash
If you are writing a shell script and want any messages to appear in the system logger you can just use the logger command to do this.
Here is an example on my Slackware system:
$ logger -t TEST "This is a test message"$ cat /var/log/messagescat: /var/log/messages: Permission denied$ su -Password:# cat /var/log/messagesAug 23 17:44:47 slackbook TEST: This is a test message
Encrypting Files using OpenSSL
Let’s say we have a file that contains sensitive information and we want to encyrpt it. You can encrypt a file very easily using the openssl command:
$ cat secret.txtThis file contains some very secret stuff$ openssl enc -e -aes-256-cbc -pbkdf2 -a -salt -in secret.txt -out secret.encenter aes-256-cbc encryption password: <enter-a-password>Verifying - enter aes-256-cbc encryption password: <enter-a-password>$ cat secret.encU2FsdGVkX19Rnz48WjLeljd19wvNOhQy+zzYwxCANezCTkqpGMl9zs4HdwdUzZjlVQkUsCJ7b0rUpRi83UlcwA==
Finding the SSL Directory on a Server
I’ve had situations where I was configuring a secure connection to an application and needed to know where the SSL certificates are stored on the server. You can easily find out this information using the openssl and grep commands:
$ openssl version -a | grep OPENSSLDIROPENSSLDIR: "/etc/pki/tls"
Processing The Results of The Find Command
As mentioned in the previous post, the find command searches for files, but it has another very useful feature in that it can also perform an action on the files it finds.
I am a vim user, and let’s assume that I want to find my editor’s backup files in the current directory trees. These filesall end with a tilda (~) character. We would use this command to search for them:
Using the Find Command to Search for Files
One of the most useful and flexible GNU utilities is the find command. Understanding how to use this command is very important to make you Linux life more efficient.
The general syntax of the find command is:
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression]
That looks like a lot, but most of the time you may only need 2 things:
find [path] [expression]