Difference between revisions of "Useradd"

From wikieduonline
Jump to navigation Jump to search
(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...")
 
Line 44: Line 44:
 
== See also ==
 
== See also ==
 
* [[macOS]]: [[MacOS/Create a user from command line|sysadminctl]]
 
* [[macOS]]: [[MacOS/Create a user from command line|sysadminctl]]
* [[sudo]]
+
* {{Linux Commands privileges}}
 
* [[OpenSSH]]
 
* [[OpenSSH]]
 
* [[Ansible]]: [[DevOps/Ansible/User ssh access]]
 
* [[Ansible]]: [[DevOps/Ansible/User ssh access]]
* [[userdel]]
 
* [[usermod]]
 
 
* <code>[[groups]]</code> or <code>[[id]]</code> commands to list groups of a user. sudo usermod -a -G root USERNAME
 
* <code>[[groups]]</code> or <code>[[id]]</code> commands to list groups of a user. sudo usermod -a -G root USERNAME
 
* [[chmod]]
 
* [[chmod]]

Revision as of 11:11, 11 December 2019

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: