Showing entries with tag "Linux".

Found 23 entries

Basic snmpd.conf file to monitor ethernet ports of a Linux box

I need to monitor the Ethernet interfaces of a Linux VM. This is the perfect job for snmpd which you can get by installing net-snmp and then applying a basic config. Here is a simplified config that will get you basic read-only access for a community and subnet.

# /etc/snmp/snmpd.conf
rocommunity snmp-read 165.92.231.0/24
rocommunity snmp-read 10.3.1.0/24
rocommunity snmp-read localhost
syslocation "City, State"
syscontact  "Admin <user@domain.com>"

You can test your new SNMP configuration with snmpwalk

snmpwalk -v 2c -c snmp-read 127.0.0.1
Leave A Reply

Linux: repeatedly run a command to monitor output

If you need to repeatedly run a command and view the output changes over time then check out my cli_watch.pl script. I was watching a RAID array rebuild slowly and needed a way to see the progress over time.

Usage: cli_watch.pl [--delay 15] [--line 3] command

Run my_command every 15 seconds:

cli_watch.pl --delay 15 'my_command | grep stuff'

Filter output to only line 2:

cli_watch.pl --line 2 'ping -c 1 192.168.5.222'

Leave A Reply - 1 Reply

Linux: fd is a much better file search

Linux has had the find command since the 1970s. It was probably great in it's day, but it's not very modern and isn't the most intuitive tool. I found fd (sometimes called fd-find) which is infinitely better and easier to use. If you're looking for a simple way to search your filesystem, it's the way to go.

fd-find is hosted on Github.

Leave A Reply

Linux: Check if a process is running

You can list all the running processes on a Linux box with ps aux, but often you're looking for a specific process. This is pretty easily accomplished with grep:

ps aux | grep /usr/sbin/sshd

The problem with this is that you often pick up you own grep in the output:

$ ps aux | grep /usr/sbin/sshd
root         883  0.0  0.0  76640  7428 ?        Ss   Oct18   0:00 /usr/sbin/sshd -D -oCiphers...
bakers     11691  0.0  0.0  12148  1104 pts/0    S+   08:09   0:00 grep --color=auto /usr/sbin/sshd

The quick and dirty solution is to do some trickery with a regular expression and grep:

$ ps aux | grep -P '/usr/sbin/[s]shd'
root         883  0.0  0.0  76640  7428 ?        Ss   Oct18   0:00 /usr/sbin/sshd -D -oCiphers...

The square brackets tell grep to match a character class with only one character in it. This prevents grep from picking up itself, but still matches what you want.

Leave A Reply

Linux: Using the parallel command to use all your cores

Linux has a cool utility named parallel that let's you run many tasks simultaneously. It's useful for older tasks that aren't multi-threaded. I often use it to encode MP3s in parallel because lame only uses one core. On a modern machine with 8+ cores, it's much more efficient to use them all at the same time. You need to feed parallel a list of files and then use the {} pragma to replace the string with the incoming filename. Parallel has similar syntax to xargs.

find src/dir -type f -iname *.mkv | parallel vid2mp3 '{}' --track 1 --out /var/tmp/

This sample command will invoke parallel command, detecting how many cores are available, and spawn that many threads of the output command. All references to {} will be replaced with the incoming filename.

Leave A Reply

Linux: Regenerate SSH host keys

Fedora and CentOS automatically regenerate SSH host keys on bootup if the key files are missing. This makes it easy to trigger regeneration as you simply remove the keys, and reboot the server. Other distributions are not quite as forgiving and require manual intervention. These are the steps I've used on Debian to get updated host keys.

rm /etc/ssh/ssh_host_*
ssh-keygen -f /etc/ssh/ssh_host_rsa_key     -N '' -q -t rsa
ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key   -N '' -q -t ecdsa
ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -q -t ed25519

ls /etc/ssh/*key* -lsh

systemctl restart sshd
Leave A Reply - 2 Replies

Linux file IO redirection matrix

Borrowing from this amazing post about Linux file IO redirection here is a cool table that breaks down how to get the data where you want it.

Syntax TermStdOut TermStdErr FileStdOut FileStdErr File
command > no yes yes no create
command >> no yes yes no append
command 2> yes no no yes create
command 2>> yes no no yes append
command &> no no yes yes create
command &>> no no yes yes append
command | tee yes yes yes no create
command | tee -a yes yes yes no append
command |& tee yes yes yes yes create
command |& tee -a yes yes yes yes append
Leave A Reply

Fedora 31 major package versions

Fedora 31 has these versions of some core packages:

Package Version
Apache 2.4.41
GCC 9.2.1
Kernel 5.3.7
Perl 5.30.0
PHP 7.3.11
Vim 8.1.2198
Git 2.23.0
MariaDB 10.3.17
Leave A Reply

Linux: Fedora 29 major package versions

Fedora 29 has these versions of some core packages:

Package Version
Apache 2.4.34
GCC 8.2.1
Kernel 4.18.16
Perl 5.28.0
PHP 7.2.11
Vim 8.1.483
Git 2.19.1
Leave A Reply

SSH to hosts with older ciphers

We have some older Cisco equipment that runs SSH with some untrusted ciphers. Specifically the key exchange is still using SHA1, which modern Linux distributions have deprecated. You may see something like this:

Unable to negotiate with 234.234.234.234 port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1

You can work around this by putting this in your ~/.ssh/config

Host 234.234.234.234
    KexAlgorithms +diffie-hellman-group1-sha1

Borrowed from StackExchange.

Leave A Reply

Linux: Fedora 28 major package versions

Fedora 28 has these versions of some core packages:

Package Version
Apache 2.4.33
GCC 8.0.1
Kernel 4.16.3
Perl 5.26.1
PHP 7.2.5
Vim 8.0.1788
Git 2.17.0
Leave A Reply

Fedora: Enable h264 video on Firefox with Fedora 28

The h264 video codec is the most popular codec on the internet right now. Unfortunately it's patent encumbered so it cannot be included in Firefox unless Mozilla were to pay a licensing fee. To enable h264 support in Firefox on Fedora 28 you'll need to enable the RPM Fusion repository.

dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm \
https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

After you've configured RPM Fusion you'll need to install some FFMpeg libraries to handle the actual h264 decoding:

dnf install ffmpeg-libs compat-ffmpeg28
Leave A Reply

Linux: Fedora 27 major package versions

Fedora 27 has these versions of some core packages:

Package Version
Apache 2.4.29
GCC 7.2.1
Kernel 4.13.3
Perl 5.26.1
PHP 7.1.11
Vim 8.0.1187
Git 2.14.3
Leave A Reply - 1 Reply

Linux: Fedora 26 major package versions

Fedora 26 has these versions of some core packages:

Package Version
Apache 2.4.26
GCC 7.1.1
Kernel 4.11.8
Perl 5.24.1
PHP 7.1.6
Vim 8.0.662
Git 2.13.0
Leave A Reply

Linux: Debian 9 major package versions

Debian 9 ships with these versions of some core packages:

Package Version
Apache 2.4.25
GCC 6.3.0
Kernel 4.9.0
Perl 5.24.1
PHP 7.0.19
Vim 8.0.550
Git 2.11.0
Leave A Reply

Tar: Auto detecting the compression type

The Linux tar command has a cool feature to auto-detect the file compression based on the archive suffix.

-a, --auto-compress

use archive suffix to determine the compression program

This allows you to change file compressions by just changing the archive suffix:

tar -cvpaf /tmp/backup.tar.gz ~/
tar -cvpaf /tmp/backup.tar.bz2 ~/
tar -cvpaf /tmp/backup.tar.xz ~/

This saves you having to specify -z -j or -J respectively.

Leave A Reply

Linux: Fedora 25 major package versions

Fedora 25 has these versions of some core packages:

Package Version
Apache 2.4.23
GCC 6.2.1
Kernel 4.8.6
Perl 5.24.0
PHP 7.0.12
Vim 7.4.1989
Leave A Reply

Linux: Remote desktop client

For a long time I have used rdesktop on Linux to connect to remote Windows boxes. Redhat is deprecating rdesktop because it does not the support modern encryption technologies that Window uses. Instead they are recommending that users switch to xfreerdp. Here is the syntax you'll need to use to connect to a remote Windows server:

xfreerdp /u:Administrator /v:10.1.8.93
Leave A Reply

Linux: Build a base VM image

When a new version of a distro comes out I like to build a base VM image that I can use later to turn up new VMs quicker. Here are the steps I use on a CentOS or Fedora VM image:

  1. Install minimal system via GUI
  2. Install default packages
  3. Setup Vim config
  4. Disable/remove SELinux
  5. Setup default bash prompt
  6. Remove SSH keys
  7. rm /etc/ssh/*key*
  8. New keys will be generated on boot
  9. Set generic hostname
    1. echo new-virt.web-ster.com > /etc/hostname
  10. Remove mac address line from network config
  11. Replace chrony with NTPd
    1. yum -y swap chrony ntp
  12. Enable NTPd
  13. Disable firewalld
    1. systemctl mask firewalld
  14. Set grub default boot time to two seconds
    1. perl -pi -e 's/GRUB_TIMEOUT=\d/GRUB_TIMEOUT=2/' /etc/default/grub
    2. grub2-mkconfig -o /boot/grub2/grub.cfg
  15. Shutdown VM and archive the disk image
Leave A Reply

Linux: write a network image to an SD card

If you have a fast network connection you can read an ISO directly from the Internet and write to a flash drive, or SD card. Just pipe curl to dd (requires root) and you're done.

curl ftp://mirror.web-ster.com/centos/7.2.1511/isos/x86_64/CentOS-7-x86_64-NetInstall-1511.iso | sudo dd of=/dev/sde
Leave A Reply

Linux: Fedora 22 major package versions

Fedora 22 has been released and I gathered the versions of some core packages:

Package Version
Perl 5.20.2
PHP 5.6.9
Vim 7.4.640
Apache 2.4.12
Kernel 4.0.4
Leave A Reply

Linux: Count CPU instructions

Zend published this infographic and it got me thinking about CPU instructions. According to the graphic, the Wordpress homepage required 9.4 billion machine instructions to render, but they've optimized PHP7 and it's now down to 2.6 billion. To count CPU Instructions on a Linux box you can use the perf command:

perf stat -e instructions <my_command>

In comparison, some very simple Linux commands take a significant amount of instructions:

# Approximately 640,000 instructions
perf stat -e instructions echo '' 

# Approximately 2 million instructions
perf stat -e instructions cd ~

# Approximately 700,000 instructions
perf stat -e instructions clear
Leave A Reply

Sending a file attachment from the command line

Finally I found out how to send a file attachment from the command line.

echo "This is the body" | mutt -s "Subject Line" -a file.txt -- email@domain.com

Borrowed from souptonuts

Leave A Reply