Use visudo To Edit The sudoers File

Today’s article may take a different format than most, as it’s just an article telling you to use visudo to edit the sudoers file. This type of article doesn’t lend itself to my normal formatting and should be considered akin to a Public Service Announcement. 

So, let’s start with the basics:

What Is The sudoers File?

Very simply, the sudoers file is the file on your system that decides who has permission to use elevated permissions via sudo. The sudoers file is pretty important and it’s easy to make mistakes while editing it. Fortunately, there’s some protection you can use while editing the sudoers file.

If you’re curious, we normally recommend using sudo instead of using root because sudo only gives the command elevated permissions while root always has elevated permissions. Those folks reading my site are generally fairly new to Linux and, as such, I strongly suggest using sudo instead of just logging in as root. Sure, it’s more of a hassle, but it’ll help save you from yourself.

What is visudo?

The visudo command will open your sudoers file with your default text editor. In many cases that will be Vim, but Nano is starting to be the default for more distros. I prefer the latter.

The visudo command defines itself like so:

visudo — edit the sudoers file

Further, and helpfully, you’ll find this in the description:

visudo edits the sudoers file in a safe fashion, analogous to vipw(8). visudo locks the sudoers file against multiple simultaneous edits, provides basic sanity checks, and checks for parse errors before installing the edited file. If the sudoers file is currently being edited you will receive a message to try again later.

So, as you can see, using visudo will help protect you from mistakes.

NOTE: While visudo can save you from syntax mistakes, it will do nothing to prevent you from entering the wrong information. If you open a second terminal and pre-authenticate for sudo, and do so quickly enough, you can then use that second terminal to fix it (re-editing the sudoers file).

Use visudo To Edit The sudoers File:

The sudoers file is located at /etc/sudoers and is a plain text file. It’s just a configuration file, like so many other configuration files. But, as described above, it’s a very important file. It’s also possible to mount the drive with a live Linux instance to edit the file, but that’s not something I’d recommend. Besides, if you use visudo to edit the sudoers file that shouldn’t be a problem.

You don’t need to specify anything when you want to edit the sudoers file. You don’t have to specify the file’s location. The visudo command knows where your sudo file is (unless you’ve modified this, as you can make a second config file and edit that) all by itself. If you want to use visudo to edit the sudoers file, you simply need this command in your favorite terminal:

The very first line of that file says this:

This file MUST be edited with the ‘visudo’ command as root.

I realize what it says, but in this case, you can replace ‘root’ with ‘sudo’ which will elevate your permissions to those of root. So, we’re sort of still using root to edit the file, but we’re technically just using sudo.

Closure:

There is my PSA about using visudo to edit that sudoers file. You must do so, especially if you’re new. You might be able to avoid a syntax error, but there’s no reason to not use visudo which will check for that sort of stuff.

I suppose the name comes from a time when Vi was still popular and it’s not a complete solution. You can still enter garbage and get garbage results. If you’re unprepared for the potential consequences, you might want to avoid editing the sudoers file until you’ve gained some confidence and have more familiarity with the tools Linux provides.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Let’s Password Protect A File

Today’s article is a fun one, where we’ll learn how to password protect a file using something called GPG. It’s not complicated. You can learn how to password protect a file in just a few minutes. You can then send these files out and other people can decrypt them – assuming you’ve shared the password with them.

We all have secrets. They’re not all digital, but they could be. We may also want to be able to share files that have private information in them, meaning you only want people with the password to open it. Though, I suppose, brute force is always an option – but you can at least make it difficult by using a complex password, preferably one that you didn’t generate yourself.

So, what is GPG? GPG stands for “GNU Privacy Guard”. It’s fairly standard and used quite a bit. There are other applications, like PGP, but I think all of you folks that use a ‘full’ distro will have GPG installed by default. It’s one of those tools that you might not use all that often, but it seems to be included by default in a lot of places. I suspect that’s because other things rely on GPG, but I’m way too lazy inept to look that up.

By the way, the GPG man page describes it as:

gpg – OpenPGP encryption and signing tool

That GPG is what we’re going to be using for this exercise. Trust me, it’s easier than you might think. 

Password Protect A File:

Do I have to mention it? Of course I do! It’s time for your favorite thing, an open terminal ready for your commands. You can open your default terminal by pressing CTRL + ALT + T.

With your terminal now open, the command to password protect a file would be:

The -c flag stands for encryption. It should then ask you for a password, that you’ll need to enter twice, and then it will make an encrypted copy of the file with a .gpg extension. The original file will still exist, so this isn’t encrypting that original file. It’s making an encrypted copy and you’ll want to safely delete the original file if that’s your intention.

Now, to open the new <file_name>.gpg file, you’ll need to use the following command:

Now, when I went to open that with the same computer and the same session it didn’t ask for a password. I shipped it to another computer and it did just that. I do not know why.

When you successfully open the password protected file, it will ask you if you want to overwrite the original. This shouldn’t happen when you ship it to someone else unless they happen to already have a file with that specific name. It also will let you say don’t want to overwrite the file and let you pick a new file name for the unencrypted content.

Closure:

You can actually do this with a folder if you’d prefer. It’s just specifying a folder instead of a file. The process is exactly the same. So, like I said in the start, it’s a really easy task to password protect a file. The terminal is useful for all sorts of stuff.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Find Out Which Window Manager You’re Using

Today’s article shouldn’t be all that long or difficult, as we simply go over how to find out which window manager you’re using. In the Linux world, this is often abbreviated as “WM” but we’ll avoid using the abbreviation ’cause of search engines. Yeah, search engines have a lot to do with how this (and every other) site is configured – including deciding how I write articles.

Yay! We need to appeal to you AND the algorithms. We’re all slaves to the machine! 

So, what is a window manager? We can cheat and cite the Arch Wiki (a brilliant source for all things Linux). They define window managers as:

A window manager (WM) is system software that controls the placement and appearance of windows within a windowing system in a graphical user interface (GUI). It can be part of a desktop environment (DE) or be used standalone.

Further, there are the following clues:

Window managers are X clients that control the appearance and behaviour of the frames (“windows”) where the various graphical applications are drawn. They determine the border, title bar, size, and ability to resize windows, and often provide other functionality such as reserved areas for sticking dockapps like Window Maker, or the ability to tab windows like Fluxbox. Some window managers are even bundled with simple utilities like menus to start programs or to configure the window manager itself.

Now, in modern times, most of you will be using the window manager that came with your distro and you’ll just leave it as the default. This article is for that person – the person who didn’t install their window manager and doesn’t know which window manager they’re using.

Which Display Manager Are You Using:

You guessed it! You’re going to need to use a terminal for this. Oh, there are surely GUI ways to do this, but I know you have a terminal. You can just press CTRL + ALT + T to open your default terminal.

With your terminal, you can run the following command:

If that command doesn’t spit out the information you’re after, you may need to install it. Your trusty default terminal should happily tell you how to install wmctrl, but it’d be (in Debian/Ubuntu/Mint/etc) something like this:

Of course, if you have Neofetch installed, you can just run Neofetch. Like ‘wmctrl’, you might need to install it. You might as well install it, though you could just as easily use Screenfetch. You get to pick which one you want to use, but it’ll be listed under the aforementioned abbreviation of “WM”. See? Foreshadowing! I can’t believe you read this nonsense.

So, there are a few options to find out which window manager you’re using. You can pick which you like most, but either of the *fetch applications will give you more system information. Do what you must…

Closure:

I planned on another article, but this one seemed like a more interesting article to write today. As it seemed more interesting to share how to find which window manager you’re using, I decided to go with that one.

These “easier” articles take about the same amount of time to write. The subject is often decided by what I feel is the most interesting. You can always start your own site and write along with me. There’s room for all of us!

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Have Infinite Bash History

Today we’re going to have a good time because we’re learning how you can have infinite Bash history. There’s a bit more to it and not all of you will want an infinite Bash history. But, for those that do, we’re going to accomplish that right here in this article!

First, I’m assuming you’re using Bash as your shell. The odds are really good that you’d know if you’re not using Bash, as Bash is pretty much the default. Bash is the interactive shell you’re using, known as Bourne Again Shell. If you don’t know what shell you’re using, I covered that in an article about determining the shell you’re using.

Side Note: I sometimes write articles that are meant to preface another article, but then I forget and don’t write the additional article. I suppose that helps keep things interesting…

So, as you know, when you type a command into the terminal that command is stored in a file typically called ~/.bash_history – a hidden file in your home directory. Well, there’s a limit to how much history that file will retain and this is Linux – meaning that, of course, you can change that value. Today, we’ll be changing that value – making it ‘infinite’.

No, of course, it’s not really infinite. There’s a finite amount of disk space you have. This being a plain text file, it takes up very little space. While it’s not technically infinite you can store a whole lot of entries in your Bash history. We’ll set it to infinite, but I’ll show you how to set it to any value you want.

Ready?

Infinite Bash History:

As you can see, this is a Bash thing. That’s a good sign that you’ll need an open terminal. You can press CTRL + ALT + T and your default terminal should open. See? We’re already making progress!

With your terminal open, we’re going to edit another hidden file. The name of this file is .bashrc and it’s a file that stores things like terminal settings.

The tool we’ll be using is ‘nano‘. Click that link to learn about Nano, including how to install Nano should Nano not come preinstalled in your chosen distro. As you may know, Nano is one of my favorite text editors. We use Nano a lot around here.

Start with opening the ~/.bashrc file with nano, like so:

Scroll to the bottom and add the following lines:

Any negative value, in this case, -1, will result in an infinite history. However, you can make that value any number you want. When you’re done adding those lines, you have to save the file. Remember, to save a file in Nano, you just press CTRL + X, then Y, and then ENTER.

You could make the value 5000, for example. That’d simply look like this:

The sky is the limit. You can make that value any number you want, but all negative values will be treated the same. If the value is negative, it means you’ve got an infinite Bash history. Don’t forget to save any changes with Nano, as instructed above.

Now, you could reboot or log out to make the new settings take effect, or you can simply tell your system to reload the file to make the changes take immediate effect. That’s an easy command, simply use:

As you can see, infinite isn’t infinite (nothing is in the real world, according to current observations) and you don’t have to choose the infinite setting. You can pick whatever numbers you fancy and the process is the same.

Closure:

There you go, you now know how to set up your system to have an infinite Bash history. Well, an infinite ~/.bash_history if you prefer. With that setting engaged, you’re limited only by your creativity, fanaticism, and disk space. Go nuts with it! They make bigger disks! (Also, it takes up very little space.)

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To Tell If You’re Using Wayland Or X11

Today’s article will be an interesting one, for at least a subset of readers, as we learn how to tell if you’re using Wayland or X11. The command isn’t all that difficult and is just a single command that should work with everything, but the topic might confuse some of you.

Frankly, if you ask this question to the majority of users, you’re probably going to find out that they’re still using X11. The move to Wayland has been a process, that started back in 2008. The goal is to replace X and provide a much better set of protocols.

That’s what Wayland is… It’s a set of protocols dealing with how things are displayed on your monitor. X is also a set of protocols for the display server – and it dates back to 1984. Without X (or something else), we’d have been staring at nothing but terminal outputs this entire time, so it is kind of a big deal.

That doesn’t mean the current X implementation is that old on your device, it just means that it has been the default for a long time. The upstart, that is Wayland, is meant to take care of a variety of flaws – including potential security flaws. That’d be a subject way too deep to get into today.

Currently, some distros are confident with Wayland and release distros that default to Wayland. Some offer it as an option, without it being the default. The GNOME and KDE desktop environments are currently the closest to being ‘Wayland-ready’. It’s a slow process!

So, you might not know if you’re using Wayland or X11 and this article tells you how to check just that.

Are You Using Wayland Or X11:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

With your terminal open, just run the following command: (It should work in any distro, regardless of which display server you’re running.)

The output should look a lot like this:

Unless you’re using Wayland. In that case, it’d look something like this:

If the output says x11,  you’re not using Wayland. If it says Wayland, you’re using Wayland. I probably didn’t need to specify this, but I did. This way, you can be completely sure if you’re using Wayland or x11.

Closure:

See? There’s a fun command you can play around with. If you’re not sure if you’re using Wayland or X11, this command will get you sorted quickly and easily. There are all sorts of great things you can do with an open terminal and a little bit of knowledge.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.