Useradd

From wikieduonline
Revision as of 17:32, 8 December 2019 by Welcome (talk | contribs) (Created page with " == Add user using Ansible == <pre> - user: name: YOUR_USER_NAME shell: /bin/bash groups: sudo append: yes password_lock: yes </pre> == Ad...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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[1] 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
passwd -u $USERNAME
passwd: password expiry information changed.

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

useradd[2] command.

-m --create-home
-s --shell


You can also consider activating passwordless sudo for your accounts.

See also

  • http://man7.org/linux/man-pages/man8/useradd.8.html
  • http://man7.org/linux/man-pages/man8/useradd.8.html
  • Advertising: