useradd

From wikieduonline
Revision as of 09:55, 25 October 2023 by Welcome (talk | contribs)
Jump to navigation Jump to search

useradd[1] - create a new user or update default new user information (man)

useradd -m YOUR_USERNAME -s /bin/bash
        -m, --create-home

useradd -m YOUR_USERNAME --uid #### --gid #### -s /bin/bash --create-home

useradd -m YOUR_USERNAME -g your-group -s /bin/bash --create-home

-c

Add user using Ansible

 - user:
     name: YOUR_USER_NAME
     shell: /bin/bash
     groups: sudo
     append: yes
     password_lock: yes

Add user using bash

Example creating a user in Ubuntu with bash shell, ~/.ssh directory and part of group sudo using useradd[2] command:

#!/bin/bash
USERNAME="Your_user_name"

# Create user and add to sudo group
  useradd  --create-home -s /bin/bash $USERNAME
  sudo usermod -aG sudo $USERNAME 

#Create ssh directory and lock password login
  mkdir /home/$USERNAME /home/$USERNAME/.ssh
  chown $USERNAME.$USERNAME /home/$USERNAME /home/$USERNAME/.ssh 
  passwd -l $USERNAME 


passwd -l $USERNAME // for disabling password login
passwd -u $USERNAME // will unlock account if needed


After creating user you can copy ssh key using ssh-copy-id and modifying sudo for giving new user privileges.

useradd command

useradd[3] command.

-m --create-home
-M, --no-create-home
-N, --no-user-group
-s --shell

useradd -m YOUR_USERNAME -s /bin/bash


You can also consider activating passwordless sudo for your accounts.

Related commands

Activities

See also

Advertising: