Sandra Henry-Stocker

Author Archives: Sandra Henry-Stocker

Looking into Linux user logins with lslogins

One convenient way to list details about user logins on a Linux system is to use the lslogins command. You'll get a very useful and nicely formatted display that includes quite a few important details.On my system and likely most others, user accounts will start with UID 1000. To list just these accounts rather than include all of the service accounts like daemon, mail and syslog, add the -u option as shown in the example below.$ sudo lslogins -u UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS 0 root 151 0 0 root 1000 shs 68 0 0 12:35 Sandra H-S 1001 nemo 0 0 0 2021-Jan05 Nemo Demo,,, 1002 dbell 0 0 1 Dory Bell 1003 shark 2 0 0 7:15 Sharon Hark 1004 tadpole 0 0 0 2020-Dec05 Ted Pole 1005 eel 0 0 0 2021-Jan11 Ellen McDay 1006 bugfarm 0 0 0 2021-Jan01 Bug Farm 1008 dorothy 0 0 1 Dorothy Reuben 1012 jadep 0 0 1 2021-Jan04 Jade Jones 1013 myself 0 0 0 2021-Jan12 My Self 1014 marym 0 0 0 2020-Mar20 Mary McShea 1017 gijoe 0 0 0 GI Joe 65534 nobody 0 0 1 nobody What the lslogins command does is grab Continue reading

Looking into Linux user logins with lslogins

One convenient way to list details about user logins on a Linux system is to use the lslogins command. You'll get a very useful and nicely formatted display that includes quite a few important details.On my system and likely most others, user accounts will start with UID 1000. To list just these accounts rather than include all of the service accounts like daemon, mail and syslog, add the -u option as shown in the example below.$ sudo lslogins -u UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS 0 root 151 0 0 root 1000 shs 68 0 0 12:35 Sandra H-S 1001 nemo 0 0 0 2021-Jan05 Nemo Demo,,, 1002 dbell 0 0 1 Dory Bell 1003 shark 2 0 0 7:15 Sharon Hark 1004 tadpole 0 0 0 2020-Dec05 Ted Pole 1005 eel 0 0 0 2021-Jan11 Ellen McDay 1006 bugfarm 0 0 0 2021-Jan01 Bug Farm 1008 dorothy 0 0 1 Dorothy Reuben 1012 jadep 0 0 1 2021-Jan04 Jade Jones 1013 myself 0 0 0 2021-Jan12 My Self 1014 marym 0 0 0 2020-Mar20 Mary McShea 1017 gijoe 0 0 0 GI Joe 65534 nobody 0 0 1 nobody What the lslogins command does is grab Continue reading

Automating responses to scripts on Linux using expect and autoexpect

The Linux expect command takes script writing to an entirely new level. Instead of automating processes, it automates running and responding to other scripts. In other words, you can write a script that asks how you are and then create an expect script that both runs it and tells it that you're ok.Here's the bash script:#!/bin/bash echo "How are you doing?" read ans [Get regularly scheduled insights by signing up for Network World newsletters.] Here's the expect script that provides the response to the query:#!/usr/bin/expect set timeout -1 spawn ./ask # ask is name of script to be run expect "How are you doing?\r" send -- "ok\r" expect eof When you run the script, you should see this:To read this article in full, please click here

Checking network connections with arp and ip neigh

Linux provides two very useful tools for diagnosing network troubles: arp and ip neigh.The arp command is a tool that allows you to display the IP-address-to-MAC-address mappings that a system has built so that it doesn't have to fetch the same information repeatedly for systems it communicates with. In doing this, arp allows you to discover and display details about systems on your network.The other is the arp command's younger brother, ip neigh, which can also display and manipulate arp tables. In this post, we'll take a look at how these commands work and what they can tell you.To read this article in full, please click here

2021 New Year’s resolutions for Linux users

It's a good idea to start each year with some ideas about how to make the new year better--even when it comes to working with Linux. This post offers some suggestions on how you might get more value and enjoyment from Linux in 2021.Commit favorite commands to aliases or scripts Linux commands make it easy to manipulate files and command output, but the cleverest commands can be very difficult to remember and reuse. Commit them to a script or alias, on the other hand, and you can give them meaningful names that are easy to remember  and use them easily  any time you need. Here's an example of a complicated Linux command turned into an alias:To read this article in full, please click here

Searching Wikipedia on the Linux command line with wikit

Have you ever imagined looking up some topic on Wikipedia while you're working on the Linux command line? What about displaying the results in a different language? Yes, it's possible. In fact, it's quite easy. The tool that provides this service is called wikit (Wikipedia IT).To check if wikit is installed on your system, just type "which wikit". If it is, you will get a response like this:$ which wikit /usr/local/bin/wikit If it's not, you can install it, but you might need to first install nodejs which wikit depends on and maybe npm as well with a command like one of these:To read this article in full, please click here

Using the Linux arping command to ping local systems

The arping command is one of the lesser known commands that works much like the ping command.The name stands for “arp ping” and it’s a tool that allows you to perform limited ping requests in that it collects information on local systems only. The reason for this is that it uses a Layer 2 network protocol and is, therefore, non-routable. The arping command is used for discovering and probing hosts on your local network.[Get regularly scheduled insights by signing up for Network World newsletters.] If arping isn’t installed on your system, you should be able take care of that with one of these commands:To read this article in full, please click here

Creating your own cowsay messenger

One of the sillier, but still fun, tools available on Linux is called "cowsay". It's used to display a phrase along with an ASCII art image of a cow.The cowsay command allows you to create messages that are less likely to be overlooked and might come across as just a little friendlier than the other thousand or so messages most of us get every day. For example:$ cowsay This is cowsay! _________________ < This is cowsay! > ----------------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || || Once cowsay is installed on your system, you can create cute little messages – and you're not limited to displaying a cow! In fact, if you wander over to the cowsay's directory –  /usr/share/cowsay/cows – you'll see that there's a fairly large collection of files available. Each includes a different image. You can choose from images as diverse as a snowman and a stegosaurus. If you want to greet your Australian friends using cowsay, you might try using the koala.To read this article in full, please click here

Using pidof and pgrep to list process IDs

The pidof and pgrep commands provide listings of process IDs (PIDs) for process names that you provide as arguments. This post shows how to use these commands and illustrates the differences between them with a series of examples.pidof There are a number of ways to determine the PID of a process running on a Linux system, but the easiest is probably a command called pidof. Read this as “PID of” and you’ll have an easy time remembering it. Using this command, you can get the PID of a process by typing “pidof” and specifying the process name. For example:$ pidof bash 1262005 If you were to run the ps command without arguments, you will get a list of the processes that you’re running in your current shell. The command below shows where the response above comes from:To read this article in full, please click here

Fetching Linux system details with screenfetch and neofetch

Two very useful tools for extracting essential details on your Linux system OS and hardware are screenfetch and geofetch.Each of these tools is actually a lengthy bash script that fetches the information from your system for you and presents it in an attractive manner with the distribution logo on the left and details on the right--essentially "screen shots" of your system. Neither is likely to be installed on your system by default, but each can be installed with a single command.screenfetch You can install screenfetch with sudo apt install screenfetch or sudo yum install screenfetch. Screenfetch is a script with nearly 6,500 lines. It will automatically detect your distribution and display the distribution, kernel, uptime, number of packages installed, shell you're using, overall and available disk space, CPU, GPU and memory (in use and available). It also displays an ASCII art rendition of the logo related to whatever distribution it's run on, but you can turn this off if you want to see just the list of details.To read this article in full, please click here

Many ways to sort file content on Linux

The Linux sort command can arrange command output or file content in a lot more ways than you might realize--alphabetically, numerically, by month and randomly are only some of the more interesting choices. In this post, we take a look at some of the more useful sorting options and explain how they differ.The default The default sort might seem fairly straightforward. Digits come first, followed by letters and, for each letter, lowercase characters precede uppercase characters. You can expect to see this kind of ordering:012345aAbBcCdDeEASCII order Looking at the numeric byte values for each of these letters, you may note that what you see above is not the "natural order" as far as ASCII is concerned.To read this article in full, please click here

Monitoring failed login attempts on Linux

Repeated failed login attempts on a Linux server can indicate that someone is trying to break into an account or might only mean that someone forgot their password or is mistyping it. In this post, we look at how you can check for failed login attempts and check your system's settings to see when accounts will be locked to deal with the problem.One of the first things you need to know is how to check if logins are failing. The command below looks for indications of failed logins in the /var/log/auth.log file used on Ubuntu and related systems. When someone tries logging in with a wrong or misspelled password, failed logins will show up as in the lines below:To read this article in full, please click here

How to sort ps output

The ps command is key to understanding what's running on your Linux system and the resources that each process is using. It's useful to know how to display the information that ps provides in whatever way helps you focus on the problem you're trying to resolve. One aspect of this is being able to sort the output of the ps aux command by any column to highlight particular information, such as how much memory processes are using or how long they've been running.The trick involves using the ps command's --sort option and knowing how to specify the column that you want to use for the sort. By default, ps sorts by process IDs (PIDs), showing the smallest first. PID 1 will appear at the top of the list, right under the column headings. The rest will follow in numeric order.To read this article in full, please click here

Tagging commands on Linux

Tags provide an easy way to associate strings that look like hash tags (e.g., #HOME) with commands that you run on the command line. Once a tag is established, you can rerun the associated command without having to retype it. Instead, you simply type the tag. The idea is to use tags that are easy to remember for commands that are complex or bothersome to retype.Unlike setting up an alias, tags are associated with your command history. For this reason, they only remain available if you keep using them. Once you stop using a tag, it will slowly disappear from your command history file. Of course, for most of us, that means we can type 500 or 1,000 commands before this happens. So, tags are a good way to rerun commands that are going to be useful for some period of time, but not for those that you want to have available permanently.To read this article in full, please click here

Using the Midnight Commander to browse Linux directories

Midnight Commander – the "mc" command – provides an easy way to browse directories and to view, move, delete, compare, change and edit files. Similar in some ways to ranger, mc makes it easy to move around directories and offers side-by-side file/directory listings that work independently of each other. In addition, it provides a very wide range of actions that you can take through simple menu choices.To start Midnight Commander, simply type "mc" in a terminal window. When you open mc, both the left and right sides of the display will look the same and will show the contents of whatever directory you started in. You can switch sides using the tab key or simply by clicking on a directory or file in the side of the display. You can select a file or directory simply by clicking on it. You can also browse directory contents using the up and down arrow keys.To read this article in full, please click here

How to modify user-account settings with usermod

There are quite a few changes you can make to user accounts on Linux systems: setting them up, deleting or disabling them, adding or removing users from secondary groups, changing usernames or UIDs, moving home directories, changing users’ shells, altering account expiration timing, and so on.One command that can make nearly all of these changes easier is usermod. The only real constraints are 1) that the accounts you intend to change must already exist on the system (this command won’t set them up from scratch), and 2) that the affected users should probably not be logged in when you make these changes.The basic syntax for the command is usermod [options] LOGIN but that options section has a lot more possibilities than you might anticipate. In addition, sudo permissions will be required for this command since superuser access is required to set up or change nearly all user account settings.To read this article in full, please click here

How to modifying user-account settings with usermod

There are quite a few changes you can make to user accounts on Linux systems: setting them up, deleting or disabling them, adding or removing users from secondary groups, changing usernames or UIDs, moving home directories, changing users’ shells, altering account expiration timing, and so on.One command that can make nearly all of these changes easier is usermod. The only real constraints are 1) that the accounts you intend to change must already exist on the system (this command won’t set them up from scratch), and 2) that the affected users should probably not be logged in when you make these changes.The basic syntax for the command is usermod [options] LOGIN but that options section has a lot more possibilities than you might anticipate. In addition, sudo permissions will be required for this command since superuser access is required to set up or change nearly all user account settings.To read this article in full, please click here

Disowning a process in Linux

When you want a process to continue running even after you log off a Linux system, you have a couple options.One of them is to use the disown command. It tells your shell to refrain from sending a HUP (hangup) signal to the process when you log off. So, the process continues running. This can be very handy whenever you start a process and then, for some reason, you can’t stay logged in and wait until it finishes.[Get regularly scheduled insights by signing up for Network World newsletters.] The disown command is a shell built-in. This means that you don’t have to install it to use it, but it also means that it won’t be available if you use a shell that doesn’t support it. For those of us using bash and related shells (zsh, ksh etc.), disown should be available and you can verify this with a command like this that lists shell built-ins and then looks for "disown":To read this article in full, please click here

How to enforce password complexity on Linux

Deploying password-quality checking on your Debian-based Linux servers can help ensure that your users assign reasonably secure passwords to their accounts, but the settings themselves can be a bit misleading.For example, setting a minimum password length of 12 characters does not necessarily mean that all your users' passwords will actually have 12 or more characters.Let's stroll down Complexity Boulevard and see how the settings work and examine some that are worth considering.[Get regularly scheduled insights by signing up for Network World newsletters.] The files that contain the settings we're going to look at will be:To read this article in full, please click here

How to enforce password complexity on Linux

Deploying password-quality checking on your Debian-based Linux servers can help ensure that your users assign reasonably secure passwords to their accounts, but the settings themselves can be a bit misleading.For example, setting a minimum password length of 12 characters does not necessarily mean that all your users' passwords will actually have 12 or more characters.Let's stroll down Complexity Boulevard and see how the settings work and examine some that are worth considering.[Get regularly scheduled insights by signing up for Network World newsletters.] The files that contain the settings we're going to look at will be:To read this article in full, please click here