Useradd
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 loginpasswd -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
- macOS: sysadminctl
- sudo
- OpenSSH
- Ansible: DevOps/Ansible/User ssh access
- userdel
- usermod
groups
orid
commands to list groups of a user. sudo usermod -a -G root USERNAME- chmod
Advertising: