Paul Sutton

adding

Bash scripting 23 – users

To add new users to a system, we can use the command. You will need to have root privileges for this, so you need to prefix with sudo, e.g.

**Permissions, the initial user you create when setting up the pi, has sudo or admin privileges. Additional users will not. Unless you take steps to give that user those permissions.**

sudo useradd <user>

The rest of the process is interactive, in this example I am adding the user gopher to the raspberry Pi4 system we are also using for testing cron.

sudo adduser gopher
Adding user `gopher' ...
Adding new group `gopher' (1001) ...
Adding new user `gopher' (1001) with group `gopher (1001)' ...
Creating home directory `/home/gopher' ...
Copying files from `/etc/skel' ...
New password: 
Retype new password: 
passwd: password updated successfully
Changing the user information for gopher
Enter the new value, or press ENTER for the default
	Full Name []: Gopher
	Room Number []: 0
	Work Phone []: 0
	Home Phone []: 0
	Other []: 0
Is the information correct? [Y/n] y
Adding new user `gopher' to supplemental / extra groups `users' ...
Adding user `gopher' to group `users' ...

I can now login to the user gopher on the Raspberry Pi with

$ ssh gopher@192.168.1.202
gopher@192.168.1.202's password: 
Linux raspberrypi 6.12.20+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.12.20-1+rpt1~bpo12+1 (2025-03-19) aarch64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
gopher@raspberrypi:~ $ 

To change the password on a GNU/Linux system, use

passwd

To delete a user, use the userdel command, I am not going into this here, so as with other commands, there is a man page

man userdel
userdel - delete a user account and related files

Tags

#Bash,#Bashscripting,#BashScripting#users,#adding


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay