Category Archives: UNBLOG Tutorials (EN)

THINK UNBLOG Knowledge Network for Tutorials, Howto’s, Workaround, DevOps Code for Professionals. The posts are made on demand contributed by professionals

XScreenSaver sonar must be setuid to ping

When I invoke the XScreenSaver Sonar or lock the screen, the Sonar XScreenSaver displays “sonar must be setuid to ping”

XScreenSaver sonar must be setuid to ping

Last weekend was a rainy Sunday, so I thought it would be a good time to upgrade the Linux Mint. My Thinkpad is running Linux Mint they I would upgarde from Linux Mint 21 (Vanessa) to Linux Mint 22 (Wilma). For those who are not familiar with the beautiful Linux Mint desktop. Linux Mint is based on the Ubuntu distribution, so Debian is the underlying system. Debian is the exemplary open source operating system what I prefer and mainly use for the servers.

One of the features I like on the Linux desktop is the Sonar XScreenSaver. Sonar shows the active hosts in the local network which are recognized by using ping as a screen saver. When I try to enable the XScreenSaver Sonar in the control center, it appers “sonar must be setuid to ping”.

cause

The Sonar program executed out from XScreenSaver must be installed as setuid root in order to ping hosts. This is because root privileges are needed to create an ICMP RAW socket.

Solution

First we find Sonar, which is not located under the same path on all distributions. You can easily find the location of Sonar with using the locate command.

$ locate sonar | head -n 1
/usr/libexec/xscreensaver/sonar

With head we see the first line with path where sonar is.

Now run the command as follows in the terminal shell to set permission.

$ sudo chmod +s /usr/libexec/xscreensaver/sonar

The s permissions instead of x in the owner permissions means that the sticky bit (suid) is enabled. So this file will be executed with root permissions by all users.

XScreenSaver setuid sonar ping

Note. some distributions Sonar is be under a different path.

$ sudo chmod +s /usr/lib/xscreensaver/sonar

Finaly check whether the permission has been set.

$ ls -ld /usr/libexec/xscreensaver/sonar
-rwsr-sr-x 1 root root 127448 Mar 31 19:32 /usr/libexec/xscreensaver/sonar

Conclusion

On most Unix systems, the Sonar program must be installed as setuid root in order to ping hosts. This is because root privileges are needed to create an ICMP RAW socket. Privileges are disavowed shortly after startup (just after connecting to the X server) so this is believed to be safe:

$ sudo chown root:root sonar
$ sudo chmod u+s sonar

It is not necessary to make it setuid on MacOS systems. Because on MacOS, unprivileged programs can ping by using ICMP DGRAM sockets instead of ICMP RAW.

In ping-mode, the display is a logarithmic scale, calibrated so that the three rings represent ping times of approximately 2.5, 70 and 2,000 milliseconds respectively.

This means that if any the hosts you are pinging take longer than 2 seconds to respond. They won’t show up; and if you are pinging several hosts with very fast response times. They will all appear close to the center of the screen (making their names hard to read.)

list files and directory with dot or no extension in Linux

File management is one of the main tasks of Linux and includes list files and directory with or without dot, the creation, modification, permissions and maintenance of files and directories. There are various scenarios in which we may need to find specific files. In these situations, Linux provides versatile commands in the bash to efficiently find files and directories.

In this tutorial, you will learn how to find dot files and directories in the GNU Bash.

In this tutorial, you will learn how to find files and directories in the GNU Bash without using any additional utilities.

First one of the most used command to list files in a directory.

$ ls -al

or using the-A, --almost-alloption do not list implied . and ..

$ ls -Al
list files in directory be using ls -Al
list files in directory be using ls -Al

Advanced list find dot files and directory

Up to this point it was not a deep knowledge and most Linux users probably know to use list files, so let us expand the commands in bash.

For example, if you only want to list files that start with a (.) dot, in Linux these are hidden files and hidden directories, the common list command is like this.

$ ls -ld .?*

This also works with almost the same output with the next command.

$ ls -dl .[^.]*

Again to list directories themselves, but not their files contents.

$ ls -dl .!(|.)

This command work only in newer GNU bash version 5 and newer.

Next list command shown long listing format for files in any directory.

$ ls -l .*

These listing can be achieved using grep, to list files and directory starting with a dot.

$ ls -a | grep "^\."
.
..
.bashrc
.config
.java
.local
.profile
.viminfo

Search for files in a directory hierarchy using find

Another powerful and versatile command isfindto search for files in a directory hierarchy, here does list files and directories starting with a dot.

$ find . -maxdepth 1 -name ".*"
.
./.local
./.profile
./.config
./.bashrc
./.java
./.viminfo

Next find in the reverse order, list only files starting without dot recursively, no directory.

$ find . -type f ! -name '.*'
./README.txt

Show only directories without dot at the beginning recursively.

$ find . -type d ! -name '.*'
./docs

Thefindcommand also allows the output to be passed to another command. Using thexargsoption does only directories that start with a dot are set permission with run chmod 755 for one directory level.

$ find . -maxdepth 1 -type d -name ".*" | xargs chmod 755

Very useful using the find command for the following scenario, here to set permission for all directories recursively with run chmod 755.

$ find . -type d -print0 | xargs -0 chmod 0755

The same to set permission of all files while run chmod 644 recursively in all directories.

$ find . -type f -print0 | xargs -0 chmod 0644

This find command is also possible with theexecoption, as shown in the next example.

$ find . -type f -exec chmod 644 {} \;

find options

-namesearching name pattern.
-type fsearch relevant files.
-type dsearch relevant directories.
-print0print the full file name on the standard output w/o trailing (LF).
-exec
-xargs
This variant of the -exec action runs the specified command on the selected files. The command line is built in much the same way that xargs builds.
-maxdepthDescend at most levels (a non-negative integer) levels of directories below the starting-points.

Search content with pattern in files recursively

find is also useful for searching patterns in files, let’s say we searching for “Red Hot Chili Peppers“, starting from the current directory recursively in all subdirectories.

$ find . -type f -print0 | xargs -0 grep -n "Red Hot Chili Peppers"
./build/README.txt:16:Red Hot Chili Peppers
./docs/Credits:2:Red Hot Chili Peppers

The output shows the path and line number of the files where the search pattern is found, enabled by the grep option -n. Note. the option -i or --ignore-case due case distinctions in patterns, default is case sensitive.

list only files and directory with no extension

If only list files and directory should be that have no extension, i.e. without dot at the end such as .txt, ran this in the command-line.

$ ls -d !(*.*)
Credits  docs

This command work only in newer GNU bash version 5 and newer.

Sometime we need more detailed output be using the long list format.

$ ls -dl !(*.*)
list files and directory that have no dot extension

Verify the bash release which is available on your system, you can hit and ran this in your /bin/bash.

$ bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.