Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

0 votes
1 answers
3148 views
Check if user exists in /etc/passwd, if they exist, create new one with prefix
Kinda stuck here, did not find any solution. Check if user exists in `/etc/passwd`, if they exist, create new one with prefix `new_the_existed_one` ``` #!/bin/bash myuser="/home/yakyak/Desktop/Exercises/newusers.txt" sed '/^[ \t]*$/d' $myuser | while read -r line do name="$line" # adduser --disabled...
Kinda stuck here, did not find any solution. Check if user exists in /etc/passwd, if they exist, create new one with prefix new_the_existed_one
#!/bin/bash

myuser="/home/yakyak/Desktop/Exercises/newusers.txt"

sed '/^[ \t]*$/d' $myuser | while read -r line
do
        name="$line"
        # adduser --disabled-login --gecos "" $name
        # check if user exist
        isthere=$(cut -d: -f1 /etc/passwd | grep "$name")

        # if user was added then make insert record into log file
        if [[ "$isthere" == "$name" ]]
        then
            echo "User already exist, creating new user.."
            adduser --disabled-login 
            # adduser --disabled-login --gecos " " $name
        fi   
done
YakyAK (23 rep)
Jan 27, 2022, 01:13 AM • Last activity: Jul 3, 2025, 03:27 PM
1 votes
1 answers
1897 views
Adding multiple user accounts on different primary/secondary groups
I am trying to create several user accounts with different groups in an imx6 board. Currently, no users are created in the device. Hence, I see 1000:1000 as my default user:group ID. The scenario I need to implement is as follows: Create two groups: grp1, grp2 Create three users: A, B, C User A: pri...
I am trying to create several user accounts with different groups in an imx6 board. Currently, no users are created in the device. Hence, I see 1000:1000 as my default user:group ID. The scenario I need to implement is as follows: Create two groups: grp1, grp2 Create three users: A, B, C User A: primary group-grp1, User B: primary group-grp1, secondary group- grp2 User C: primary group-grp2 Also, these users should be able to communicate via message queues. Users (A & B) and (B & C) should be able to communicate via message queues. Users (A & C) should not be able to communicate. In a Server/Client program, I have already set mq_open file permissions as (S_IRWXU | S_IRWXG ), so that only users in the same group can be communicated. The steps I followed to create different users are: adduser abc This creates a user with uid:guid 1000:1000 in /etc/passwd abc:$1$SqakfDG7$cPlfYQT8YmkcvgzazVKvZ/:1000:1000:Linux User,,,:/home/abc:/bin/sh addgroup grp1 addgroup grp2 Above step creates two groups in /etc/group as below. grp1:x:1001: grp2:x:1002: Create user A,B with grp1, and C with grp2 adduser -G grp1 A adduser -G grp1 B adduser -G grp2 C This creates user A in /etc/passwd A:$1$E8MDq2ND$/qU4011IYRaisq7EfJh00/:1001:1001:Linux User,,,:/home/A:/bin/sh B:$1$l2iSdPAh$ggD5NQAC1nJzbVfNVO/Kk.:1002:1001:Linux User,,,:/home/B:/bin/sh C:$1$2Y6v67Wz$TYNxHBltTNeCDhAnnAFd3.:1003:1002:Linux User,,,:/home/C:/bin/sh And in /etc/group A:x:1003: B:x:1004: C:x:1005: As you can see users A and B has the same group id (grp1) (i.e. 1001), and my server/client program successfully run. **The issue is to add group B into the secondary group "grp2".** Typing "id A" "id B" and "id C" gives me: uid=1001(A) gid=1001(grp1) groups=1001(grp1) uid=1002(B) gid=1001(grp1) groups=1001(grp1) uid=1003(C) gid=1002(grp2) groups=1002(grp2) Tried adding user "B" to "grp2" using usermod command as explained in https://unix.stackexchange.com/questions/274200/primary-and-secondary-groups usermod -a -G grp2 B but "id B" doesn't change uid=1002(B) gid=1001(grp1) groups=1001(grp1) I even tried adding user "B" to groups grp1 and grp2 when creating it for the first time adduser -G grp1,grp2 B However, I get the following error. adduser: unknown group grp1,grp2 Any idea what could I have done wrong? Thanks alot!!
radar101 (11 rep)
Aug 9, 2017, 12:32 PM • Last activity: Jun 24, 2025, 12:01 AM
15 votes
3 answers
28360 views
How to add "system" local user like mysql or tomcat?
My system has many users, I've never created, like `mysql` or `tomcat`. These users have no home directories inside `/home` Obviously, a daemon program runs under these users. What is the term for such users? How to create such a user of my own? For example, I wish to create a user for `deluged`, bu...
My system has many users, I've never created, like mysql or tomcat. These users have no home directories inside /home Obviously, a daemon program runs under these users. What is the term for such users? How to create such a user of my own? For example, I wish to create a user for deluged, but I don't want to create and remember a password for it and also don't want to allow somebody to login with this user from console. How to accomplish this?
Dims (3425 rep)
Sep 30, 2015, 05:30 PM • Last activity: Jun 11, 2025, 09:23 AM
1 votes
2 answers
6014 views
How to avoid getting "sudo: Account or password is expired, reset your password and try again"
I am trying to add user e.g. `amit` to group amit,as below. root# groupadd -g 1500 -f amit root# useradd amit -m -G sudo -u 1500 -g 1500 -o -p "amit" However, when I try to switch to user `amit` it gives out the message as below: root# sudo su - amit sudo: Account or password is expired, reset your...
I am trying to add user e.g. amit to group amit,as below. root# groupadd -g 1500 -f amit root# useradd amit -m -G sudo -u 1500 -g 1500 -o -p "amit" However, when I try to switch to user amit it gives out the message as below: root# sudo su - amit sudo: Account or password is expired, reset your password and try again Changing password for root. May I please know, why am I getting this message, what should I do in order to avoid getting this message and get directly switched to amit user.
Pravin.2087 (153 rep)
Oct 16, 2021, 08:35 AM • Last activity: May 7, 2025, 07:01 AM
0 votes
2 answers
72 views
Can't add user to the group properly
Need to create user www-data in group ubuntu to make NGINX to serve a website. /etc/passwd file: www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin ubuntu:x:1000:1000:ubuntu:/home/ubuntu:/bin/bash Trying: root@ubuntu-HP-ZBook-Studio-G3:/home/ubuntu# useradd -g ubuntu www-data useradd: user 'www-da...
Need to create user www-data in group ubuntu to make NGINX to serve a website. /etc/passwd file: www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin ubuntu:x:1000:1000:ubuntu:/home/ubuntu:/bin/bash Trying: root@ubuntu-HP-ZBook-Studio-G3:/home/ubuntu# useradd -g ubuntu www-data useradd: user 'www-data' already exists This one confuses me. Yes, there is a user www-data in group www-data, but I want to create another user www-data in another group ubuntu. Why it isn't letting me? root@ubuntu-HP-ZBook-Studio-G3:/home/ubuntu# usermod -a -G ubuntu www-data root@ubuntu-HP-ZBook-Studio-G3:/home/ubuntu/front# getent group ubuntu ubuntu:x:1000:www-data root@ubuntu-HP-ZBook-Studio-G3:/home/ubuntu/front# id www-data uid=33(www-data) gid=33(www-data) groups=33(www-data),1000(ubuntu) but /etc/password file isn't reflecting any changes and the website isn't being served. What's the proper way to achieve the goal?
jurijus01 (21 rep)
Jan 12, 2025, 12:58 AM • Last activity: Apr 13, 2025, 06:42 AM
16 votes
1 answers
39413 views
What steps to add a user to a system without using useradd/adduser?
I was browsing through some Linux questions and saw this interesting question. *What steps to add a user to a system without using `useradd`/`adduser`?* The one possible way that comes to my mind is, - Add an entry for the user in `/etc/passwd` file. - Add an entry for the group in `/etc/group` file...
I was browsing through some Linux questions and saw this interesting question. *What steps to add a user to a system without using useradd/adduser?* The one possible way that comes to my mind is, - Add an entry for the user in /etc/passwd file. - Add an entry for the group in /etc/group file. - Create the home directory for the added user. - Set the new user password using the passwd command. I tested the above approach and it worked fine. Is this the only possible way or is there any other work around to achieve this?
Ramesh (40416 rep)
Sep 1, 2014, 10:19 PM • Last activity: Feb 13, 2025, 04:21 PM
46 votes
3 answers
186820 views
bash: adduser: command not found [Debian Buster]
**Question**: What is the most-ideal way to add new users in Debian? `adduser` appears to be missing on my system, any tips? **Log**: `bash: adduser: command not found` ______________________ **Edit**: `adduser` does appear to be installed ``` adduser is already the newest version (3.118). ``` Is is...
**Question**: What is the most-ideal way to add new users in Debian? adduser appears to be missing on my system, any tips? **Log**: bash: adduser: command not found ______________________ **Edit**: adduser does appear to be installed
adduser is already the newest version (3.118).
Is is possible to manually execute it as a binary? Where is the applications stored?
Jefferysons (591 rep)
Feb 4, 2020, 06:45 AM • Last activity: Dec 27, 2024, 07:58 PM
9 votes
1 answers
1223 views
adduser allows weak password - how to prevent?
I want to enforce my password policy to both new users and existing ones, but when I run `adduser` on Ubuntu 24, it allows me to add a weak password. ```lang-shellsession $ sudo adduser handsm [sudo] password for superuser: info: Adding user `handsm' ... info: Selecting UID/GID from range 1000 to 59...
I want to enforce my password policy to both new users and existing ones, but when I run adduser on Ubuntu 24, it allows me to add a weak password.
-shellsession
$ sudo adduser handsm
[sudo] password for superuser: 
info: Adding user `handsm' ...
info: Selecting UID/GID from range 1000 to 59999 ...
info: Adding new group `handsm' (1001) ...
info: Adding new user handsm' (1001) with group handsm (1001)' ...
info: Creating home directory `/home/handsm' ...
info: Copying files from `/etc/skel' ...
New password: 
BAD PASSWORD: The password is shorter than 10 characters
Retype new password: 
passwd: password updated successfully
You can see it warning, and then when I repeat the weak password it accepts it anyway! My policy works fine for existing users who change their password. What am I missing? FWIW, the same problem applies for useradd:
-shellsession
$ sudo useradd test375
$ sudo passwd test375
New password: 
BAD PASSWORD: The password is shorter than 10 characters
Retype new password: 
passwd: password updated successfully
machinist (335 rep)
Dec 18, 2024, 11:13 AM • Last activity: Dec 19, 2024, 12:23 PM
1 votes
1 answers
2168 views
create a linux user with create files and write permissions without sudo access
I want to create a user in such a way that it can create a file and update the contents of the file. useradd username For `sudo`, we can create a username and link it to `sudo` as shown below: useradd username sudo But I don't want to give `sudo`-access, and without `sudo`-access I am unable to crea...
I want to create a user in such a way that it can create a file and update the contents of the file. useradd username For sudo, we can create a username and link it to sudo as shown below: useradd username sudo But I don't want to give sudo-access, and without sudo-access I am unable to create or update files.
kasinos (33 rep)
May 6, 2015, 12:17 PM • Last activity: Dec 18, 2024, 01:22 PM
0 votes
0 answers
36 views
How to adduser in a mounted partition without chrooting?
I would like to add a user in an SD image with an ARM Linux. Since my host computer is x86, I cannot just `chroot` into the mounted image. Is there a way to add a user to a filesystem at a relative path, with `adduser` or `useradd` or somehow else?
I would like to add a user in an SD image with an ARM Linux. Since my host computer is x86, I cannot just chroot into the mounted image. Is there a way to add a user to a filesystem at a relative path, with adduser or useradd or somehow else?
xealits (2267 rep)
Nov 19, 2024, 02:38 AM
0 votes
2 answers
50 views
When to useradd
I'm writing a daemon in C which needs to do some things as a separate user from root. I will call this user "testuser". My program is installed by its makefile. My question is thus, when should this user testuser be added? I could add it at the end of the install target: ``` install: something somet...
I'm writing a daemon in C which needs to do some things as a separate user from root. I will call this user "testuser". My program is installed by its makefile. My question is thus, when should this user testuser be added? I could add it at the end of the install target:
install:
        something
        something
        useradd -r testuser
however if the user is already added (for example by a previous install) this will fail. -useradd -r testuser would surpress this error but this seems like bad practice. Also, another problem with doing it during make install would be if we are not actually installing the daemon for this system, e.g. make install DESTDIR=something. Should I leave the useradd to the system administrator and simply make the daemon fail with an error message if the user is not present? What are the conventions?
spinosarus123 (175 rep)
Jul 4, 2024, 03:53 PM • Last activity: Jul 4, 2024, 06:19 PM
7 votes
1 answers
11384 views
usermod to change user password is not working
I have created a user using useradd myuser Then, I tried to change the user's password with usermod --password mypwd myuser (I know a plain password on the command-line is not a good way.) I have tried to login as `myuser` with `mypwd`. But it's failing with an "incorrect password" message. I could...
I have created a user using useradd myuser Then, I tried to change the user's password with usermod --password mypwd myuser (I know a plain password on the command-line is not a good way.) I have tried to login as myuser with mypwd. But it's failing with an "incorrect password" message. I could use passwd myuser (this works fine). There are some constraints, so I am trying to use usermod. Am I missing anything in usermod? or Are there any alternatives to change passwords other than passwd username?
RBB (1039 rep)
Aug 31, 2016, 08:15 AM • Last activity: Apr 30, 2024, 06:20 AM
-1 votes
2 answers
7618 views
What is the default SHA512 salt used in passwd and for the hash stored in the shadow file?
I want to add a user using useradd and specify an encrypted password using the -p flag. I learned that the unix system that I am on uses a SHA512 hash for storing passwords in the /etc/shadow file. When I look in /etc/pam.d/common-password, it says this: # Explanation of pam_unix options: # # The "s...
I want to add a user using useradd and specify an encrypted password using the -p flag. I learned that the unix system that I am on uses a SHA512 hash for storing passwords in the /etc/shadow file. When I look in /etc/pam.d/common-password, it says this: # Explanation of pam_unix options: # # The "sha512" option enables salted SHA512 passwords. Without this option, # the default is Unix crypt. Prior releases used the option "md5". # # The "obscure" option replaces the old `OBSCURE_CHECKS_ENAB' option in # login.defs. # # See the pam_unix manpage for other options. # here are the per-package modules (the "Primary" block) password [success=1 default=ignore] pam_unix.so sha512 I just need to know what the salt is, so that I can generate the hash and use it with my useradd ... ... -p INSERT_HASHED_PASS_HERE
Fuad (99 rep)
Jun 6, 2017, 09:11 PM • Last activity: Mar 28, 2024, 10:44 AM
4 votes
2 answers
20703 views
What variables are valid within /etc/default/useradd file?
My `/etc/default/useradd` file is as follow: # useradd defaults file GROUP=100 HOME=/home INACTIVE=-1 EXPIRE= SHELL=/bin/bash SKEL=/etc/skel CREATE_MAIL_SPOOL=yes `man` page for `useradd` provides many obvious options for when I use the `useradd` binary. It also says in the `man` page: /etc/default/...
My /etc/default/useradd file is as follow: # useradd defaults file GROUP=100 HOME=/home INACTIVE=-1 EXPIRE= SHELL=/bin/bash SKEL=/etc/skel CREATE_MAIL_SPOOL=yes man page for useradd provides many obvious options for when I use the useradd binary. It also says in the man page: /etc/default/useradd Default values for account creation. But it doesn't specify what values are valid within this file. I have tried using the options for the useradd binary in this file but they seem to be ignored. 2015/04/02 Update: So I should probably do some clarifications:
I am used to the debian style useradd and adduser

I'm working now, in a CentOS system and there really only is useradd. The whole point in any of this work is to modify the base user creation for a standard practice, by default: $ sudo useradd someuser $ cat /etc/passwd someuser:x:1002:1002::/home/someuser:/bin/bash $ groups someuser someuser : someuser I was hoping that I could just modify /etc/default/useradd to set some basics like: GROUPS=wheel,dialout,tftp DIR_MODE=1770 But these sorts of mods to the /etc/default/useradd file are just ignored. I could just write some simple bash script to feed useradd the defaults, but would rather not if there's just some simple config I am overlooking.

Thanks

parsecpython (215 rep)
Mar 25, 2015, 08:06 PM • Last activity: Feb 8, 2024, 01:22 PM
0 votes
1 answers
110 views
Adding an account via SSH not working with openssl
I am trying to add a user account to my remote server (running on Ubuntu 22.04) via SSH using below script: ```bash #!/bin/bash protect="y" ssh -i ssh_key root@server.ip <<END sudo deluser testuser if [[ "$protect" =~ ^[yY]*$ ]]; then sudo useradd -p $(openssl passwd -1 "password") testuser && echo...
I am trying to add a user account to my remote server (running on Ubuntu 22.04) via SSH using below script:
#!/bin/bash

protect="y"
ssh -i ssh_key root@server.ip <
The confirmation message User added successfully is showing and the user is added normally. Except I can't login to that account with these credentials. When I try to execute these commands one by one directly on the server, everything works fine and I can login to that account, so I assumed it would be some quotes escaping issue, and I tried some variantes including:
\""password"\"
"\"password"\"
\""password\""
"\"password\""
But none worked. Please help me.
dzboot02 (103 rep)
Feb 2, 2024, 10:58 AM • Last activity: Feb 2, 2024, 05:28 PM
0 votes
2 answers
58 views
File Permission of a User with No Additional Groups
Using a Rocky Linux server, I created a user using the following command, ``` sudo adduser foobar ``` and user `foobar` is now a member of group `foobar`. We can confirm with the following. ``` foobar$ id uid=1111(foobar) gid=1111(foobar) groups=1111(foobar) ``` Notice that the `uid` and the `gid` a...
Using a Rocky Linux server, I created a user using the following command,
sudo adduser foobar
and user foobar is now a member of group foobar. We can confirm with the following.
foobar$ id
uid=1111(foobar) gid=1111(foobar) groups=1111(foobar)
Notice that the uid and the gid are the same. Now, for files and directories owned by foobar, are the owner permissions the same as group permissions? __Example__ For the following directory,
drwxrwx---  1  foobar  foobar  my_dir
curiously, user baz who does NOT belong to group foobar has write access under my_dir.
bash
baz$ id
uid=2222(baz) gid=10000(group1),10001(group2)
baz$ touch my_dir/test  # (?)
baz$ ls my_dir
test
The (?) line above: how is baz able to write into my_dir when the 'others' bits are turned off?
Sekots Reivan (103 rep)
Dec 6, 2023, 05:09 PM • Last activity: Dec 7, 2023, 02:18 AM
0 votes
2 answers
177 views
im new to linux and learning how to add a new user
I'm trying to create a user with first and last name and home directory in `Users/username`, with an expiration date, inactive, with a default UID and GID in the DKEL_dir `/etc/skel2`. This is what I ran on CentOS: ``` sudo useradd -m -d /Users/username -s /bin/default/useradd -e $(date. -d "2 days...
I'm trying to create a user with first and last name and home directory in Users/username, with an expiration date, inactive, with a default UID and GID in the DKEL_dir /etc/skel2. This is what I ran on CentOS:
sudo useradd -m -d /Users/username -s /bin/default/useradd -e $(date. -d "2 days ago" "+%Y-%m-%d") -f -k /etc/skel2 Scott walker
The result I got was:
useradd:invalid numeric argument '-k'
Jonathan Spires (1 rep)
Dec 3, 2023, 01:51 PM • Last activity: Dec 3, 2023, 02:33 PM
0 votes
0 answers
181 views
Restart systemd service when new user created
I need to restart a systemd service (running as root) every time a new user is created. I saw that some systems have a way to make an adduser hook but this isn't an option in RHEL8. What is the best (least invasive; most secure) way to do this? Currently only thing I can think of is adding a script...
I need to restart a systemd service (running as root) every time a new user is created. I saw that some systems have a way to make an adduser hook but this isn't an option in RHEL8. What is the best (least invasive; most secure) way to do this? Currently only thing I can think of is adding a script to /etc/profile.d but I'm not sure if there's a way to make it run scripts as root (without doing something insecure)
ridderhoff (101 rep)
Oct 9, 2023, 03:50 PM
37 votes
4 answers
129646 views
Why is the home directory not created when I create a new user?
I created a new user (testuser) using the `useradd` command on an Ubuntu server Virtual machine. I would like to create a home directory for the user and also give them root provileges. However, when I login as the new user, it complains that there is no home directory. What am I doing wrong?
I created a new user (testuser) using the useradd command on an Ubuntu server Virtual machine. I would like to create a home directory for the user and also give them root provileges. However, when I login as the new user, it complains that there is no home directory. What am I doing wrong?
Beginner (1990 rep)
Jan 31, 2015, 02:35 PM • Last activity: Sep 27, 2023, 09:33 AM
0 votes
1 answers
9910 views
How do you add a user using --gecos Linux Ubuntu?
I am trying to create a script that adds a user, but I have to do it in a non-interactive way without the default prompts of the adduser command. The instructions I have state that I should use --grecos, but I have looked everywhere to get more information on this and I cannot find anything helpful....
I am trying to create a script that adds a user, but I have to do it in a non-interactive way without the default prompts of the adduser command. The instructions I have state that I should use --grecos, but I have looked everywhere to get more information on this and I cannot find anything helpful. The best that I found was this: enter image description here But I don't know what the empty string represents (" ") and I do not know what the argument "username" represents. Is it that the username will be named an empty string? Would someone be able to explain? This is what is supposed to be done in the script: enter image description here Would anyone be able to help me with this? Thank you all very much!
NewCoderBH1694 (9 rep)
Dec 9, 2022, 07:57 PM • Last activity: Sep 3, 2023, 07:48 AM
Showing page 1 of 20 total questions