Editing Useradd
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | + | <code>useradd</code><ref>https://linux.die.net/man/8/useradd</ref> - create a new user or update default new user information | |
− | <code>useradd</code><ref>https://linux.die.net/man/8/useradd</ref> - 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 | + | -m --create-home |
− | <code>useradd -m YOUR_USERNAME --[[uid]] #### --[[gid]] #### -s [[/bin/bash]] --create-home</code> | + | * <code>useradd -m YOUR_USERNAME --[[uid]] #### --[[gid]] #### -s [[/bin/bash]] --create-home</code> |
− | |||
− | |||
== Add user using [[Ansible]] == | == Add user using [[Ansible]] == | ||
Line 22: | Line 20: | ||
== 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: | ||
+ | <pre> | ||
+ | #!/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 | ||
+ | </pre> | ||
:<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 | ||
− | After creating user you can copy ssh key using | + | After creating user you can copy ssh key using [[ssh|ssh-copy-id]] and modifying [[sudo]] for giving new user privileges. |
== useradd command == | == useradd command == | ||
Line 52: | Line 50: | ||
− | You can also consider activating | + | You can also consider activating [[passwordless sudo]] for your accounts. |
== Related commands == | == Related commands == | ||
Line 60: | Line 58: | ||
* <code>[[adduser]]</code> ([[BusyBox]]) | * <code>[[adduser]]</code> ([[BusyBox]]) | ||
* <code>[[groups]]</code>, <code>[[chgrp]]</code> | * <code>[[groups]]</code>, <code>[[chgrp]]</code> | ||
− | * [[Cisco IOS]]: | + | * [[Cisco IOS]]: [[username]] |
+ | * [[Sftp configuration]] | ||
* [[FreeIPA]]: <code>[[ipa user-add]]</code> | * [[FreeIPA]]: <code>[[ipa user-add]]</code> | ||
− | * [[macOS]]: | + | * [[macOS]]: <code>[[dscl]] . -create /User/USERNAME_HERE</code> |
− | |||
− | |||
* <code>[[~/.ssh/]]</code> | * <code>[[~/.ssh/]]</code> | ||
* [[Cisco IOS]]: [[Associate a user with default higher privileges]]: <code>[[username]]</code> | * [[Cisco IOS]]: [[Associate a user with default higher privileges]]: <code>[[username]]</code> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== See also == | == See also == | ||
* [[macOS]]: <code>[[sysadminctl]]</code> | * [[macOS]]: <code>[[sysadminctl]]</code> | ||
* {{Linux Commands privileges}} | * {{Linux Commands privileges}} | ||
+ | * {{OpenSSH}} | ||
+ | * [[Ansible]]: [[User ssh access]] | ||
* <code>[[groups]]</code> or <code>[[id]]</code> commands to list groups of a user. sudo <code>usermod -a -G root USERNAME</code> | * <code>[[groups]]</code> or <code>[[id]]</code> commands to list groups of a user. sudo <code>usermod -a -G root USERNAME</code> | ||
− | |||
[[Category:Linux commands]] | [[Category:Linux commands]] |
Advertising: