Difference between revisions of "Useradd"
Jump to navigation
Jump to search
↑ https://linux.die.net/man/8/useradd
↑ http://man7.org/linux/man-pages/man8/useradd.8.html
↑ http://man7.org/linux/man-pages/man8/useradd.8.html
Line 21: | Line 21: | ||
== Add user using bash == | == Add user using bash == | ||
Example creating a user in [[Ubuntu]] with bash shell, ~/.ssh directory and part of group [[sudo]] using <code>useradd</code><ref>http://man7.org/linux/man-pages/man8/useradd.8.html</ref> command: | Example creating a user in [[Ubuntu]] with bash shell, ~/.ssh directory and part of group [[sudo]] using <code>useradd</code><ref>http://man7.org/linux/man-pages/man8/useradd.8.html</ref> command: | ||
− | |||
− | |||
− | |||
− | # Create user and add to sudo group | + | #!/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 | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
:<code>[[passwd]] -l $USERNAME</code> // for disabling password login | :<code>[[passwd]] -l $USERNAME</code> // for disabling password login | ||
:<code>passwd -u $USERNAME</code> // will unlock account if needed | :<code>passwd -u $USERNAME</code> // will unlock account if needed |
Revision as of 12:52, 7 November 2022
useradd
[1] - create a new user or update default new user information
- Man page: https://linux.die.net/man/8/useradd
useradd -m YOUR_USERNAME -s /bin/bash -m --create-home
useradd -m YOUR_USERNAME --uid #### --gid #### -s /bin/bash --create-home
Contents
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 loginpasswd -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
jailkit
,ChrootDirectory
passwd
userdel
,usermod
adduser
(BusyBox)groups
,chgrp
- Cisco IOS: username
- Sftp configuration
- FreeIPA:
ipa user-add
- macOS:
sysadminctl -addUser USERNAME
dscl . -create /Users/USERNAME_HERE
See also
- macOS:
sysadminctl
sudo
,id
,visudo
,useradd
,userdel
,usermod
,groups
,passwd
,chown
,chmod
,chgrp
,groupadd
,groupdel
, Passwordless sudo, passwd (package),sudo --help
- OpenSSH (changelog):
/etc/ssh/sshd_config
|/etc/ssh/ssh_config
|~/.ssh/
|openSSL | sshd logs
|sftp
|scp
|authorized_keys
|ssh-keygen
|ssh-keyscan
|ssh-add
|ssh-agent
|ssh
|Ssh -O stop
|ssh-copy-id
|CheckHostIP
|UseKeychain
, OpenSSF - Ansible: User ssh access
groups
orid
commands to list groups of a user. sudousermod -a -G root USERNAME
Advertising: