salt.modules.useradd

Manage users with the useradd command

Important

If you feel that Salt should be using this module to manage users on a minion, and it is using a different module (or gives an error similar to 'user.info' is not available), see here.

salt.modules.useradd.add(name, uid=None, gid=None, groups=None, home=None, shell=None, unique=True, system=False, fullname='', roomnumber='', workphone='', homephone='', other='', createhome=True, loginclass=None, nologinit=False, root=None, usergroup=None)

Add a user to the minion

name

Username LOGIN to add

uid

User ID of the new account

gid

Name or ID of the primary group of the new account

groups

List of supplementary groups of the new account

home

Home directory of the new account

shell

Login shell of the new account

unique

If not True, the user account can have a non-unique UID

system

Create a system account

fullname

GECOS field for the full name

roomnumber

GECOS field for the room number

workphone

GECOS field for the work phone

homephone

GECOS field for the home phone

other

GECOS field for other information

createhome

Create the user's home directory

loginclass

Login class for the new account (OpenBSD)

nologinit

Do not add the user to the lastlog and faillog databases

root

Directory to chroot into

usergroup

Create and add the user to a new primary group of the same name

CLI Example:

salt '*' user.add name <uid> <gid> <groups> <home> <shell>
salt.modules.useradd.chfullname(name, fullname, root=None)

Change the user's Full Name

name

User to modify

fullname

GECOS field for the full name

root

Directory to chroot into

CLI Example:

salt '*' user.chfullname foo "Foo Bar"
salt.modules.useradd.chgid(name, gid, root=None)

Change the default group of the user

name

User to modify

gid

Force use GID as new primary group

root

Directory to chroot into

CLI Example:

salt '*' user.chgid foo 4376
salt.modules.useradd.chgroups(name, groups, append=False, root=None)

Change the groups to which this user belongs

name

User to modify

groups

Groups to set for the user

appendFalse

If True, append the specified group(s). Otherwise, this function will replace the user's groups with the specified group(s).

root

Directory to chroot into

CLI Examples:

salt '*' user.chgroups foo wheel,root
salt '*' user.chgroups foo wheel,root append=True
salt.modules.useradd.chhome(name, home, persist=False, root=None)

Change the home directory of the user, pass True for persist to move files to the new home directory if the old home directory exist.

name

User to modify

home

New home directory for the user account

persist

Move contents of the home directory to the new location

root

Directory to chroot into

CLI Example:

salt '*' user.chhome foo /home/users/foo True
salt.modules.useradd.chhomephone(name, homephone, root=None)

Change the user's Home Phone

name

User to modify

homephone

GECOS field for the home phone

root

Directory to chroot into

CLI Example:

salt '*' user.chhomephone foo 7735551234
salt.modules.useradd.chloginclass(name, loginclass, root=None)

Change the default login class of the user

name

User to modify

loginclass

Login class for the new account

root

Directory to chroot into

Note

This function only applies to OpenBSD systems.

CLI Example:

salt '*' user.chloginclass foo staff
salt.modules.useradd.chother(name, other, root=None)

Change the user's other GECOS attribute

name

User to modify

other

GECOS field for other information

root

Directory to chroot into

CLI Example:

salt '*' user.chother foobar
salt.modules.useradd.chroomnumber(name, roomnumber, root=None)

Change the user's Room Number

CLI Example:

salt '*' user.chroomnumber foo 123
salt.modules.useradd.chshell(name, shell, root=None)

Change the default shell of the user

name

User to modify

shell

New login shell for the user account

root

Directory to chroot into

CLI Example:

salt '*' user.chshell foo /bin/zsh
salt.modules.useradd.chuid(name, uid, root=None)

Change the uid for a named user

name

User to modify

uid

New UID for the user account

root

Directory to chroot into

CLI Example:

salt '*' user.chuid foo 4376
salt.modules.useradd.chworkphone(name, workphone, root=None)

Change the user's Work Phone

name

User to modify

workphone

GECOS field for the work phone

root

Directory to chroot into

CLI Example:

salt '*' user.chworkphone foo 7735550123
salt.modules.useradd.delete(name, remove=False, force=False, root=None)

Remove a user from the minion

name

Username to delete

remove

Remove home directory and mail spool

force

Force some actions that would fail otherwise

root

Directory to chroot into

CLI Example:

salt '*' user.delete name remove=True force=True
salt.modules.useradd.get_loginclass(name)

Get the login class of the user

name

User to get the information

Note

This function only applies to OpenBSD systems.

CLI Example:

salt '*' user.get_loginclass foo
salt.modules.useradd.getent(refresh=False, root=None)

Return the list of all info for all users

refresh

Force a refresh of user information

root

Directory to chroot into

CLI Example:

salt '*' user.getent
salt.modules.useradd.info(name, root=None)

Return user information

name

User to get the information

root

Directory to chroot into

CLI Example:

salt '*' user.info root
salt.modules.useradd.list_groups(name)

Return a list of groups the named user belongs to

name

User to get the information

CLI Example:

salt '*' user.list_groups foo
salt.modules.useradd.list_users(root=None)

Return a list of all users

root

Directory to chroot into

CLI Example:

salt '*' user.list_users
salt.modules.useradd.primary_group(name)

Return the primary group of the named user

New in version 2016.3.0.

name

User to get the information

CLI Example:

salt '*' user.primary_group saltadmin
salt.modules.useradd.rename(name, new_name, root=None)

Change the username for a named user

name

User to modify

new_name

New value of the login name

root

Directory to chroot into

CLI Example:

salt '*' user.rename name new_name