Score:1

Script for creating users and set password on new servers

mo flag

i want to create ubuntu user and set password automatically. i want script to run command:

useradd -s /usr/sbin/nologin username

passwd username

and set password 1234

please help me

Score:6
cn flag

There is a command called newusers for this.

The newusers command reads a file (or the standard input by default) and uses this information to update a set of existing users or to create new users. Each line is in the same format as the standard password file (see passwd(5)) with the exceptions explained below:

UserName:Password:UID:GID:comments:HomeDirectory:UserShell

An example (use id on commandline to list ids for the current user):

username:1234:1000:1000::/home/username:/usr/sbin/nologin

and you can do

sudo chmod 0600 file.txt
sudo newusers file.txt

to add those users into a system.

It is the preferred method for migrating users.

cn flag
@Raffa "and set password 1234" is in the q ;=)
Raffa avatar
jp flag
You know I didn't mean that one ;D
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.