How to add and delete users on Alpine Linux

How do I add and delete users on Alpine Linux?

Alpine Linux is a multitasking and multi-user lightweight operating system. Typically famous as a standalone OS or for Linux container systems such as Docker, LXD, and others. We can create a user for different tasks. For example, www user for static web pages and another user for managing system. Either way, adding and removing users is an essential task for developers and sysadmins. This page explains how to add and remove users on Alpine Linux.

How to add user in Alpine Linux

To create a new user account in Alpine, use the adduser command. The syntax is as follows to add a user in Alpine:
adduser {user-name}
adduser [options] {user-name}

Let us create a new user account named wendy using the adduser command, enter:
# adduser wendy
## if sudo admin configured use it ##
$ sudo adduser wendy

Sample output
Changing password for wendy
New password: 
Retype password: 
passwd: password for wendy changed by root

The adduser command would make /home/wendy/as the home directory for wendy user. Use the ls command to verify it:
# ls -ld /home/
# ls -ld /wendy/

Sample outputs:

drwxr-sr-x    2 wendy    wendy            2 May  2 21:20 /home/wendy

Alpine Linux uses the /etc/passwd file to store all usernames and encrypted passwords stored in the /etc/shadow file.

Don’t create home directory

You can tell the adduser not to create home directory by passing the -H option:
# adduser -H wendy
We can set home directory path (default is /home/$USER/) too by passing the -h /path/to/home/dir option. For instance, set path to shared AWS /efs/ filesystem as follows:
# adduser -h /efs/home/wendy wendy

Login shell

By default /bin/ash is set as the login shell for all new users and /bin/sh for system users. On the most system, I install and use bash. So we are going to set /bin/bash (or any other shell from /etc/shells file )as a login shell:
# adduser -h /efs/home/wendy -s /bin/bash wendy
To list all shell use the cat command:
# cat /etc/shells
Finally, use the id command or directly query the /etc/passwd file using the grep command to verify that user account created on Alpine Linux:
# id {username}
# grep '^username' /etc/passwd
# id wendy
# grep '^wendy' /etc/passwd

How to delete a user

Sometimes we don’t need a user account, and we can delete them from the CLI.

Delete a user account from the command Line

To remove users on Alpine use the deluser command. The syntax is:
# deluser [--remove-home] {USER}
To delete user named ‘wendy’ from the system, run:
# deluser wendy
One can remove the user and its home directory, including all other data as follows:
# deluser --remove-home wendy
And there you have it, we added and deleted users on Alpine Linux using the CLI.


This page explained how to add and remove users in Alpine Linux using the command line method. See Alpine Linux home page here for more info.

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.