Saturday, March 29, 2014

How to add a user in Linux?


1) adduser:


Syntax is as follows for useradd command:
useradd username

By default user account is locaked, you need to setup a new password:
passwd password

Eg: 

# adduser tom

# passwd tom

List of common options:


  • -c comment: Add a comment for the user


  • -D : To view default options when adding a user.


  • -d home-directory: Create a new home-directory


  • -e yyyy-mm-dd: Date for the account to be disabled


  • -f days: Number of days after the password expires until the account is disabled. (If 0 is specified, the account is disabled immediately after the password expires. If -1 is specified, the account is not be disabled after the password expires.)


  • -g group-name: Primary Group name or group number for the user's default group (group name must exist)


  • -G group-list: List of secondary additional (other than default) group names or group numbers, separated by commas, of which the user is a member (group name must exist)


  • -m: Create the home directory


  • -M: Do not create the home directory


  • -s: User's login shell (default /bin/bash)



  • 4 different methods to a user 




    Method 1: Linux useradd Command — Create User With Default Configurations





    Syntax: # useradd LOGIN-NAME








    How do I change user name (rename user name) or UID under Linux operating system?

    A. Use the usermod command to change user name under Linux. it modifies the system account files to reflect the changes that are specified on the command line.

    Syntax is as follows
    usermod -l login-name old-name

    Where,

    => The name of the user will be changed from old-name to login_name. Nothing else is changed. In particular, the user's home directory name should probably be changed to reflect the new login name.

    usermod -u UID username

    Where,
    => The numerical value of the user's ID (UID) . This value must be unique, unless the -o option is used. The value must be non-negative. Values between 0 and 99 are typically reserved for system accounts. Any files which the user owns and which are located in the directory tree rooted at the user's home directory will have the file user ID changed automatically. Files outside of the user's home directory must be altered manually.


    Task: Change username from tom to jerry

    Type usermod command as follows:
    # id tom
    # usermod -l jerry tom
    # id jerry
    # id tom


    Task: Change user tom UID from 5001 to 10000

    Type usermod command as follows
    # id tom
    # usermod -u 10000 tom
    # id tom




    No comments:

    Post a Comment