Setting up a new user: Difference between revisions

From Alpine Linux
(improve user management event only user creation)
Line 12: Line 12:


Using the command '''adduser''' will allow you to create a new user in the system.
Using the command '''adduser''' will allow you to create a new user in the system.
# adduser --help
Usage: adduser [OPTIONS] USER [GROUP]
Create new user, or add USER to GROUP
-h DIR Home directory
-g GECOS GECOS field
-s SHELL Login shell
-G GRP Group
-S Create a system user
-D Don't assign a password
-H Don't create home directory
-u UID User id
-k SKEL Skeleton directory (/etc/skel)


If no ''OPTIONS'' is set, by default when creating a new user, it will create a home directory in {{Path|/home/<username>}}, with the shell set that uses the ''root'' account (ash by default), user ID and group ID 1000+, and the GECOS field ''Linux User,,,''.
{{Cmd|adduser <username>}}


== Example creating a user ==
It will prompt to set a password for the new user, by example let's create a new user with session name "test"
{{Cmd|adduser test}}


It will prompt to set a password for the new user
  # adduser test
  # adduser test
  Changing password for test
  Changing password for test
Line 47: Line 33:
You can now ''exit'' and login to the new account.
You can now ''exit'' and login to the new account.


= TODO =
== User management commands ==
Adding user to a group?, Privilege escalation with sudo?
 
Alpine at install comes only with busybox user management commands and the following are standar for all linux distributions
 
If no ''OPTIONS'' is set, by default when creating a new user, it will create a home directory in {{Path|/home/<username>}}, with the shell set that uses the ''root'' account (ash by default), user ID and group ID 1000+, and the GECOS field ''Linux User,,,''.
 
=== adduser ===
 
Usage:
 
<pre><nowiki>adduser [OPTIONS] USER [GROUP]</nowiki></pre>
 
Create new user, or add USER to GROUP
 
* --home DIR Home directory
*    --gecos GECOS GECOS field
*    --shell SHELL Login shell named SHELL by example /bin/bash
*    --ingroup GRP Group (by name)
*    --system Create a system user
*    --disabled-password Don't assign a password so cannot login in
*    --no-create-home Don't create home directory
*    --uid UID User id
 
Those options only work for newer versions:
 
*  -k SKEL Skeleton directory (/etc/skel)
 
One thing to note is that if <pre>--ingroup</pre> isn't set then the GID is assigned to match the UID. If the GID corresponding to the provided UID already exists adduser will fail.
 
=== addgroup ===
 
Usage:
 
<pre><nowiki>addgroup [-g GID] [-S] [USER] GROUP</nowiki></pre>
 
Add a group or add a user to a group
 
* --gid GID  Group id
*  --system  Create a system group
 
Alpine base groups permissions, check for base layout package:


https://git.alpinelinux.org/alpine-baselayout/tree/group


[[Category:Newbie]]
[[Category:Newbie]]

Revision as of 13:02, 15 November 2019

Creating a user is an important step when first configuring a Linux system. Generally root account is used for administration only as it has access to the operating system and its configuration.

Overview

When Alpine Linux is first installed by default it comes with the user root with no password set. For security reasons it's always a good idea to either set a password to the user root or disabling the login to the user, which its why is suggested to run setup-alpine to change root password.

Creating an account allows it to have it's own $HOME directory and allows you to limit access to the configuration of the operating system for security reasons.

Creating a new user

Using the command adduser will allow you to create a new user in the system.

adduser <username>

It will prompt to set a password for the new user, by example let's create a new user with session name "test"

# adduser test
Changing password for test
New password: 
Retype password: 
passwd: password for test changed by root

The new user can be seen in

Contents of /etc/passwd

root:x:0:0:root:/root:/bin/ash . . . test:x:1000:1000:Linux User,,,:/home/test:/bin/ash

You can now exit and login to the new account.

User management commands

Alpine at install comes only with busybox user management commands and the following are standar for all linux distributions

If no OPTIONS is set, by default when creating a new user, it will create a home directory in /home/<username>, with the shell set that uses the root account (ash by default), user ID and group ID 1000+, and the GECOS field Linux User,,,.

adduser

Usage:

adduser [OPTIONS] USER [GROUP]

Create new user, or add USER to GROUP

  • --home DIR Home directory
  • --gecos GECOS GECOS field
  • --shell SHELL Login shell named SHELL by example /bin/bash
  • --ingroup GRP Group (by name)
  • --system Create a system user
  • --disabled-password Don't assign a password so cannot login in
  • --no-create-home Don't create home directory
  • --uid UID User id

Those options only work for newer versions:

  • -k SKEL Skeleton directory (/etc/skel)

One thing to note is that if

--ingroup

isn't set then the GID is assigned to match the UID. If the GID corresponding to the provided UID already exists adduser will fail.

addgroup

Usage:

addgroup [-g GID] [-S] [USER] GROUP

Add a group or add a user to a group

  • --gid GID Group id
  • --system Create a system group

Alpine base groups permissions, check for base layout package:

https://git.alpinelinux.org/alpine-baselayout/tree/group