Trending March 2024 # How To Add Users To A Group In Linux # Suggested April 2024 # Top 4 Popular

You are reading the article How To Add Users To A Group In Linux updated in March 2024 on the website We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested April 2024 How To Add Users To A Group In Linux

Groups are the bread and butter of a Linux system. These are special lists that allow you to group multiple users into different categories. Along with securing your system’s application privileges, it allows you to finely control how each account in the system can access and share its files and folders.

This article shows how you can use the groups utility to add and modify existing groups in Linux. Further, it will also highlight how the Linux permissions system works in conjunction with the groups system.

How Do Groups and Permissions Work?

At its core, a Linux group is a collection of users that share the same permissions and privileges for a specific file or program. Every file in the system has a set of ownership and permission bits. One of the easiest ways to find this is to run ls -l on your home directory.

That will list all the visible files and folders in the directory along with their ownership and permission bits. For the most part, the general format for this looks like:



ramces maketecheasier 8.7k Oct





chúng tôi first, third and fourth columns show both the permission and ownership bits of the current file. For example, the “rwxrwxr-x” valuetells the system that everyone can read this file, but only the user “ramces” and group “maketecheasier” can write to it.

These two bits work hand in hand to create a finely tuned access control system in Linux. The permission bits tell the system how a file can be used by the users and groups in the ownership bits.

Viewing the Group Memberships for a User in Linux

The first step to modify a group in Linux is to know which are available to a user to give you an idea of the active groups in the system.

Running the following command will list all the available groups for the current user:


Viewing the Available Groups in the System

Along with looking at user-specific groups, it is also possible to list every group in the system by running the following command:







This will print the entire “/etc/group” file in your terminal screen. Scroll through the file by pressing J or K.

By default, “/etc/group” is a colon-delimited file that contains both user and system-specific groups. Each line in thie file represents a currently active group in the machine.

The general format for each line looks like:


The group-name is the label for the group. In most cases, system groups start with an underscore to differentiate them from regular groups.

The password is an optional field to create secure groups, which is useful if you are sharing the system with multiple people.

GID is the Group ID for that particular group.

Lastly, the users field is a comma-separated list that contains all the users that are part of that group.

Note: even if you are not in the root group, you can still open files as root. Learn how to do that.

Creating a New Group in Linux

To create a new group in Linux, use the groupadd command. Unlike id, this is a utility that only deals with group creation.

For example, I can run the following command to create a new group with the name “test.”




Creating a New User With a New Group

It is also possible to create both a new user and group in a single command, which is useful when you are setting up a shell scripting account with predetermined permissions.

To do this, run the following command:












The –m flag tells useradd to create the new user’s home directory, as, by default, Linux does not create a home directory for the “test” user.

The -G flag tells useradd to create and add the “test” user to the “maketecheasier” group.

The -s flag sets the default login shell for the “test” user. In my case, I am telling the useradd utility to set the login shell for the “test” user to Bash.

Adding an Existing User to a New Group in Linux

Along with creating a group and its user, you can also add existing users to a group by running the following command:




maketecheasier user Adding Multiple Users to a New Group

Lastly, it is also possible to include multiple users to your new group. To do this, run the following command:







This will set the member roster for the “maketecheasier” group to include both “ramces” and “test.” However, it is important to note that the -M flag always replaces the users value in the “/etc/group” file.

Appending new users to your group will also require you to include the users that are already in the group. For example, running the following command will append both “alice” and “bob” to the “maketecheasier” group:






,alice,bob maketecheasier

Tip: learn how to switch to another user account with the sudo command.

Frequently Asked Questions Is it possible to edit the /etc/group file to modify a group in Linux?

While it is possible to modify the “/etc/group” file, it can potentially ruin the file’s internal format, leading to systems with non-functional groups and missing permissions. As such, it is not a good practice to edit the “/etc/group” file directly.

My new group does not show up on my user's group list. Is my machine broken?

No! By default, the Linux groups system does not apply any changes that you make to online users. This approach protects these users from any sudden system changes that may prevent them from accessing a file or program.

To update your user’s group list, either log out from the current session or restart the entire machine.

Image credit: Unsplash. All alterations and screenshots by Ramces Red.

Ramces Red

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.

By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time.

You're reading How To Add Users To A Group In Linux

Ansible Add User To Group

Introduction to Ansible Add User to Group

The following article provides an outline for Ansible Add User to Group. In Ansible, you have multiple default modules which comes with its package and you can also create customized modules using a supported scripting language like Python. The use of these module depends upon the requirements and available parameters as well as options. Some of the modules are basic and needed for day to day tasks such as user module, which is used to create, remove, update a user on remotes hosts. This is for Linux based OS on remotes hosts. For Microsoft Windows based remote hosts, there is another similar module named win_user. Here we will see user module and its alternatives to add user to group on remote hosts.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Ansible Add User to Group

In a operating system, user and groups are created to organize the privileges hierarchy. Also, to manage the user as per their roles, groups are created and assigned to those users. This is a general practice which takes place across all those operating systems which supports multiuser environment and login support. Using a configuration management automation tool like Ansible, makes such operational tasks, easy and smooth to execute when you have tens of target hosts.

Few parameters, while adding user to group.

Given below are the few parameters:

1. append: This parameter is useful when you want to append a user to a group or a list of groups.

This accepts two values:

yes: To append all the listed groups in groups field, to the user’s mapped group list or you can say, add the user to the groups specified in groups.

no: To overwrite the assigned group list of the user with only groups mentioned under groups field, meaning removing the user from all groups except mentioned in groups. This is the default option if nothing is mentioned.

2. group: To set the user’s primary group. Acceptable option is a valid group name.

3. groups: To give the list of secondary groups, to which the user will be added to. When an empty string (‘ ’) is given, user will be removed from all the groups except its primary group.

How to Add User to Group?

To add a user to a group, we can have two scenarios related to user’s existence:

User is new and need to be added to existing groups.

User is existing and need to be added to existing groups.

In both the cases, we can use command module or user module in Ansible, to add user to group. For command module, we can directly pass Linux command as plain text to run on remote hosts. For using user module, we can use either ansible to do this by passing all parameters and options on command line or ansible-playbook by mentioning all parameters and options in a playbook and execute it.

How to Remove User from Group?

To remove a user from a group or list of groups we can either use command module and pass Linux command in plain text or use user module via ansible or in a playbook and execute by ansible-playbook.

One point to note that while using user module, there is no direct way to remote a user from a group or list of groups.

We should use append field and provide the list of groups to groups section in playbook.

Examples of Ansible Add User to Group

Given below are the examples mentioned:

Example #1

Add a new user to a list of secondary groups while creating it.

This can be done by below different ways:

a. Use command module and pass Linux command to add as user and assign a list of groups as secondary group to it.


ansible all -m command -a "useradd testuser -G testgroup1,testgroup2,testgroup3"


You can check the user is created in remoted hosts and assigned groups like below:


id testuser



id testuser


b. Use ansible and pass all the parameters on command line like below:


ansible all -m user -a "name=testuser groups=testgroup1,testgroup2,testgroup3 append=yes"


Upon checking on target systems, you will find that user is created and assigned to the listed groups as secondary groups.


id testuser



id testuser


c. Use ansible-playbook and write all your requirements in a YAML file called Playbook which have all the values in key-pair form.

The playbook content will be like below:


append: yes


ansible-playbook useradd_assign_secondary_group.yaml


On remote hosts, you can check like below:


id testuser



id testuser


Example #2

For adding an existing user to a group. You can use either command module or user like above. But better we practice writing playbooks, as this is more organized. Also, the output is easily readable.

We can write a playbook like below:


append: yes

Then execute it like below:


ansible-playbook adding_user_to_group.yaml


Also, on checking remote hosts, we can see that a new group have been added to the list of secondary groups.




id testuser


Example #3

For removing a user from group, we have use append with value.

To do this, we can create playbook like below:


append: no

Then executes it like below:


ansible-playbook removing_user_from_groups.yaml


On remote hosts, if you check you will find that, the user testuser have only testuser4 as secondary group and it has been removed from rest of all secondary groups,

On remote hosts, if you check you will find that, the user testuser have only testuser4 as secondary group and it has been removed from rest of all secondary groups,


id testuser



id testuser



Adding and removing users from a group or a list of groups is a repetitive task. Which is important but confusing sometimes when doing it manually on command line. So, better practice is to maintain a playbook for such tasks and pass the actual values on real time during execution.

Recommended Article

This is a guide to Ansible Add User to Group. Here we discuss the introduction to Ansible Add User to Group with how to add user to group? how to remove user from group? and examples. You may also have a look at the following articles to learn more –

How To Add A String After Each Line In A File In Linux?


We occasionally need to make changes to files quickly, preferably from the command line. One example is adding a string to the end of each line of a file.

In this article, we’ll look at several ways to accomplish this using various Linux commands.

The sample file chúng tôi that follows will be used throughout this article −



$ touch language




A file will be created with the name of language.txt.

Output Hindi English Chinese Spanish

We’ll examine various techniques for appending the phrase “is a good language to learn.” to the end of each line in our chúng tôi file

By Using sed

In Linux, sed (stream editor) is a powerful built-in utility. It can be used to perform file functions such as find and replace, search, insertion, and deletion.


Let’s take a simple example to accomplish the given task using sed command −

$ sed



's/$/ is a good language to learn/'


i language


txt $ cat language



With the help of sed command, you will add a string after each line in the file, you can see the output by using cat command.

Output Hindi is a good language to learn English is a good language to learn Chinese is a good language to learn Spanish is a good language to learn

It is simple and quick to carry out many file functions using sed because we can alter files without even opening them.

By Using awk

With the help of awk, we can create simple programs by writing statements that specify text patterns to be looked for in each line of our file and actions to be performed when a match is discovered.

The majority of Unix versions and Unix include the scripting language awk. It is short for Aho, Weinberger, and Kernighan, the developers who worked on its construction in 1977.


With the help of above command, we can add a string after each line in the file and the output will be saved in chúng tôi file. You can view the content of chúng tôi by using cat command.

Output Hindi is a good language to learn English is a good language to learn Chinese is a good language to learn Spanish is a good language to learn By Using perl

The initial purpose of perl (Practical Extraction and Report Language) was to scan arbitrary text files, extract data from them, and create reports using the information. It combines some of the strengths of sed, awk, and sh, making it simpler and more comfortable for us to come up with rapid fixes for typical issues.


Lets execute the perl command −

$ perl





's/$/ is a good language to learn./'




Output Hindi is a good language to learn. English is a good language to learn. Chinese is a good language to learn. Spanish is a good language to learn

The output of the command is not visible on standard out. To see the changes, we may use the cat command on our input file directly. We don’t need to make a new file because perl makes changes straight to the input file.

By Using echo

The echo command, as we all know, outputs text to the standard output (STDOUT).

While the behaviour of the echo command differs slightly between shells, we’ll focus on the bash built-in version here.

Let’s combine the cat command with the run echo command −

Example Output Hindi is a good language to learn. English is a good language to learn. Chinese is a good language to learn. Spainsh is a good language to learn. Conclusion

We learned in this article how to add a string to the end of each line of a file in Linux. To accomplish this, we used sed, awk, echo, perl, and other commands. Because the methods we examined work similarly, the method we select is a matter of personal preference.

How To Rename A File In Linux

When you start learning something new, even the simplest tasks feel confusing, and that can be frustrating for anyone. Say renaming a file is one of the most basic tasks for file management, but newbies might face difficulty in renaming a file or batch renaming files in Linux. To help you with it, we have explained four easy ways to rename a file or even multiple files in Linux using the command line interface (CLI) as well as the GUI.

Renaming Files in Linux (2023)

First, we will explain how to use the mv and rename commands to rename files using the Command Line (or Terminal) in Linux. And then, we will learn how to rename or batch rename files using GUI tools, including GPRename and the native file manager in your Linux distro.

Rename Files Using the Command Line

Even though using the command line for the simplest of tasks might sound intimidating at first, it boasts a lot of features and is the fastest way to rename files in Linux. Here, we are using the mv and rename commands, and both of them will work in any Linux distribution.

Rename Files Using mv Command

The mv command stands for “move” with its primary purpose being to move both files and directories in the Linux file system. But we can also use the mv command to rename files. The syntax for the mv command is:

Note: If you use any of the -i, -f, -n flags more than once, only the final one takes effect.

Rename Single File Using the mv Command

To rename a single file using the mv command, use the below-given syntax:

The command results in the output below as confirmation, and you can verify the changes made using the ls command.

In the above example, we are renaming the file “mini-course-10.pdf” to “test-1.pdf” using the mv command. Here, the syntax looks like this:

mv -v chúng tôi test-1.pdf

After that, you can verify the change from the output of the mv command (highlighted in the image above), or you can further verify the output using the ls command. You will see the renamed file in the list of files in that directory.

Rename Multiple Files using the mv Command

The mv command can also be used to rename multiple files in a directory with some modifications. Here we will use some new commands along with the mv command. The command can prove to be difficult to understand with just raw syntax, so we have used it as an example below.

for i in *.pdf;do mv -v "$i" "${i/${i:0:4}/example}" done Rename Files Using rename Command

The rename command solves the complexity of the mv command with easy-to-use syntax for both single and multiple file renaming. The rename command generally comes pre-installed on most distros. If not, you can easily install it using a simple command:

For Debian-based systems –

sudo apt install rename

For Fedora-based systems –

sudo yum install prename

For Arch-based systems –

sudo pacman -S install rename

Since the rename command uses Perl in the backend, there are three types of regular expressions – match, substitute, and translate in Perl. The rename command uses the “substitute” and “translate” regular expressions. In the syntax above, the “s” is used to specify that you will use the substitute expression.

For RedHat, Fedora-based systems, you need to use the following command syntax:

OptionsDescription-vShows information about the current operation-nstands for “no action” and is used for testing to see how the files are going to get affected after the operation-fused to force overwrite the file name

Rename a Single File

The rename command works much like the mv command when renaming a single file. To rename a single file, use the following syntax:

Rename Multiple Files Rename Files Partially

Suppose you have used spaces in all your file names, and now, you want to replace the spaces with underscores. You can use the rename command and convert spaces to underscores using the syntax shown below:

For the above situation to replace spaces with underscores, use the given command:

Here, the is used to treat the underscore as a character and not a part of the command syntax.

Change The Case of The Filenames

With the rename command, you can even replace the lowercase characters with their respective uppercase characters and vice versa. To replace the lowercase characters with uppercase ones, use the following syntax:

And to replace uppercase characters with lowercase ones, use this syntax:

Rename Files using the GUI in Linux

The GUI method is probably a boon for those users who find the command line daunting. For the GUI method, we are using the Nautilus File manager and GPrename in Ubuntu 20.04 LTS, but rest assured that these methods will work on any distribution – albeit with slight modifications in some.

Rename Files Using File Manager

This is one of the easiest methods to rename files in Linux. Every Linux desktop distribution comes pre-installed with a file manager such as Nautilus, Dolphin, Thunar, etc. We have explained how you can use these file managers to rename files, so keep reading.

Rename A Single File Rename Multiple Files Using File Manager

2. In this context menu, select the “Rename” option. Or, you can press the F2 button on the keyboard to access the rename option.

3. This will open a new rename window, as shown below. Here, you get two options to rename the files, so let’s learn how to use both of them one by one.

Rename Using a Template:

3. Then, choose the order of naming the files from the “Automatic Number Order” drop-down menu. You can choose between Ascending, Descending, and more.

Find and replace text:

1. Enter the current common name in the “Existing Text” field. In the bottom pane, you will see the common name get highlighted.

2. In the “Replace With” text box, enter the new common name you want to replace the current name with.

Using GPRename to Rename Files

GPRename is a lightweight batch renaming tool that comes with several different options that can prove useful while renaming files using the Linux GUI. This tool can be helpful for users who find it difficult to batch rename files using their native file manager. Sadly, it doesn’t come pre-installed, but can easily be installed using the following commands:

For Debian-based systems –

For Fedora-bassed systems –

sudo dnf install gprename

For Arch-based systems –

sudo pacman -S gprename

Rename A Single File with GPRename

1. Open GPRename from the Applications menu or type gprename in the Linux Terminal.

2. Use the file system tree on the left to navigate to the desired folder. Then, select the file you want to rename in the right pane.

Rename Multiple Files with GPRename

1. As explained above, use the file system tree on the left to navigate to the desired folder. Then, select the files you want to rename and choose the appropriate option from the bottom pane.

Frequently Asked Questions

What does rm command do in Linux?

Easily Rename Files in Linux

How To Add A Line In Microsoft Word

Last Updated on August 19, 2023

Microsoft Word can be used for many things. It’s not just a tool for writing documents.

If you’re willing to go a step further with it, you can create some really great documents that are quite appealing to the eye. 

One of the features you can use in Microsoft Word is its horizontal lines. 

While on the surface, this might seem a bit anticlimactic, it’s actually a really good feature for separating big bodies of text and overall, it just makes the document you’re writing easier to read. 

But how do you add these lines in Microsoft Word? Well, read on to find out!


Insert A Line (The Fast Way)

There is actually more than one way you can insert a line in Microsoft Word. This option is by far the fastest way.

This method is called the AutoFormat feature. Certain characters in Microsoft Word are designed to be able to change into lines:



Put The Cursor On The Line

Put the cursor on the line where you want the horizontal line.



Type Three Of These Characters And Press Enter

Type three of these characters (picture below) and press Enter.

As soon as you press enter, the line will be added automatically and will look like whichever character you typed in three times.

The line extends to the full width of the page. If you have any columns you’re inserting the line to, it will match the width of the column rather than the page.

If you want to add any text above the line, just put the cursor above the line and begin typing.

This method is the quickest and easiest way to add a horizontal line to Microsoft Word.


Draw A Line

You can also draw lines in Word. They won’t look like the ones above, but if you’re looking to add a bit more flair to your document, try this method too:



Go To The Insert Tab





Decide What Location Of The Document You Want Your Lines To Be in

Decide what location of the document you want your lines to be in. Hold down on your mouse and drag the line there.


Inserting A Line Using Borders

This method lets you insert lines both horizontally and vertically using borders. This is another straightforward method, so just follow these steps:



Select The Paragraph

First, you want to select the paragraph where you want the line to be.





The Border Pattern Will Usually Be The Bottom Line On The Dropdown Menu

By default, the border pattern will usually be the bottom line on the dropdown menu. But don’t worry, you can change it.



Select The Arrow To Open The Dropdown Menu

On the Borders button, select the arrow to open the dropdown menu. You can now change the position of the line.



You Also Have The Option Of “Borders And Shading”

You also have the option of “Borders and Shading” which is at the bottom of the menu. Here you can change the width, color, height, or style of the line.


Sometimes a huge wall of text can be quite daunting to begin reading, especially if there are lots of pages included in the document. But that’s why lines are such a great feature for you to use. 

Adding lines to your document couldn’t be any easier. Microsoft Word generally likes to keep its features as simple and as accessible as possible, so you won’t have any trouble when it comes to adding your lines. 

Play around and experiment with this feature to work out what’s best for your document.

How To Add A Column Of Numbers In Bash?


This article examines how to total up numeric columns of data in a bash shell, looking at the bash tools available for the task and comparing their speed.

Using The awk Tool

We’ll start by calculating the sum of the values in a particular column using the awk (awk) program.

$ awk '{Total=Total+$1} END{print "Total is: " Total}' numbers.csv Total is: 49471228

Let’s now take a look at the timing using the “time” command −

$ time awk '{Total=Total+$1} END{print "Total is: " Total}' numbers.csv Total is: 49471228   real 0m0.228s user 0m0.141s sys 0m0.047s When The File Contains Multiple Columns

We’ve seen how to calculate sums across one row of a file using awk. Now let’s see how to calculate sums across multiple rows of a file.

$ cat prices.csv Books,40 Bag,70 Dress,80 Box,10

Here, the file chúng tôi has two columns. We now want to calculate the sum of the values in the second column.

$ awk -F "," '{Total=Total+$2} END{print "Total is: " Total}' prices.csv Total is: 200 When The File Contains a Header Line

Sometimes, text or CSV file headers also include a row containing column names. We’ll use these column names to help us understand the contents of the file. Let’s edit our chúng tôi file and add a new row at the top −

$ cat prices.csv Item,Value Books,40 Bag,70 Dress,80 Box,10 $ awk -F "," 'NR!=1{Total=Total+$2} END{print "Total is: " Total}' prices.csv Total is: 200

We’ll then look at some other methods for adding up numbers in a column, and see how the awk approach compares to them.

Iterating With The Bash Loops

Awk is a powerful tool, but we could also use a for loop to iterate over each value in our columns.

Using the expr Command

We’re going to run an experiment and see if we can use the expr function to calculate the total of the numbers inside the for loop.

$ time (sum=0;for number in `cat numbers.csv`; do sum=`expr $sum + $number`; done; echo "Total is: $sum") Total is: 49471228   real 212m48.418s user 7m19.375s sys 145m48.203s Using Arithmetic Expansion

Since the use of “expand” did not help much, we’ll try another approach using arithmetic expression −

$ time (sum=0;for number in `cat numbers.csv`; do sum=$((sum+number)); done; echo "Total is: $sum") Total is: 49471228   real 0m1.961s user 0m1.813s sys 0m0.125s

In order to calculate the total, we’ll utilize the arithmetic operator. Unlike the expr operator, the $(…) operator can handle both integers and floats.

Adding Values With the bc Command

The bc command performs calculations on expressions consisting of multiple lines. Therefore, we’ll have to concatenate the numbers into one line, separating them with an addition operator. Then we’ll pass the resulting string to bc to perform the calculation. Here are a few ways to do so.

Using The Paste Command

To start off, we’ll take a look at the “PASET” command to arrange the first ten numbers of our data set on one line.


Now that we’ve covered the basics, let’s move on to providing our input to the bc command.

Total is: 49471228   real 0m0.244s user 0m0.203s sys 0m0.063s

Using The tr Command

Let’s use the tr (transliterate) function again to create a new string from an existing one.


We added an extra zero at the beginning of the string so that we could use the bc command to perform addition. However, notice the extra ‘+’ at the end of the string. To fix this, we can simply append another zero at the end of the line.


Let’s redirect the result from the previous command to the bc command.

49471228   real 0m0.217s user 0m0.203s sys 0m0.031s

Combining tr and bc commands runs faster than using awk.

Using The sed Command

We’ll finally be using the sed command to generate our sequence.


49471228   real 0m0.343s user 0m0.281s sys 0m0.109s

To change the meaning of the newlines, use the “–z” option. Instead of interpreting the newlines as the start of each input, they will now be treated as the null characters. So, if we replaced the newlines with the plus sign (+), then we would get the following output −

You may want to use sed instead of tr if you’re working with large amounts of text.


We looked at different methods for adding up columns of numbers in a bash shell.

We began by discussing the use of the awk command. We then discussed ways to handle files that contain multiple columns or a single column with a heading.

Update the detailed information about How To Add Users To A Group In Linux on the website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!