bopslinux.blogg.se

Create a local user
Create a local user















There is a field in the /etc/passwd file that allows for a comment to be put in place. Note that by setting the UID to a specific value, the next user account you create will be incremented up from this value even if you had lower values available. Uid=1337(testaccount) gid=1337(testaccount) groups=1337(testaccount) The UID is automatically set to the next available number when using ‘useradd’ however we can explicitly set a user ID that is not currently in use with the -u option.

#Create a local user password#

Account Expiryīy default when a user account is created the password will never expire which is a bad security practice, we can define when the account should expire and require the password to be changed with the -e option, followed by the date to expire the account in the format of YYYY-MM-DD ~]# useradd testaccount -e Specify User ID (UID)

create a local user

The /sbin/nologin shell essentially denies an account from logging into the system as it has no shell defined. This simply updates the shell field in the /etc/passwd file. This can differ based on your distribution however, so you can explicitly set the shell with the -s flag as shown below. In most Linux distributions, when an account is created with the ‘useradd’ command the default shell of /bin/bash will be set. See our post on adding user accounts to groups in Linux for further information.

create a local user

When adding a user to any supplementary group, the /etc/group file will be modified to reflect this.

create a local user

Once the two groups have been created, we create the ‘testaccount’ user and add it in as a member to both of these groups. In this example, we first use ‘groupadd’ to create two groups named testgroup1 and testgroup2, the groups we want to add our user to need to exist first. ~]# useradd testaccount -G testgroup1,testgroup2 The -G flag on the other hand is generally much more useful, it allows us to specify a list of supplementary groups that the user account should be a member of. The -g flag will change the user’s primary group id (GID), which by default will be created the same as the username. When running the useradd command, we can add the user account to a group with the -g or -G flag. So far above we have covered the most simple way of creating a local user account in Linux, however the ‘useradd’ command provides us with many additional and useful options. Passwd: all authentication tokens updated successfully.Īfter setting the password, the configuration containing the hashed password is written to the /etc/shadow file. We can set a password by using the ‘passwd’ command, followed by the user account. Testaccount:x:1001:1001::/home/testaccount:/bin/bashĪt this point, the user account does not have a password set, so it is disabled by default and cannot be used. ~]# useradd testaccountĮssentially this writes the required line of configuration to the /etc/passwd file, as shown below. Here’s the most basic example of creating a local user account in Linux, in this case we run the useradd command and specify the username we want to create, which is “testaccount”.

create a local user

Here we will cover some examples of using the various syntax options with useradd in order to create a new local user account in Linux. In Linux we can create a new user account with the ‘useradd’ command.















Create a local user