A
A
Alexey Yarkov2016-10-30 11:28:10
linux
Alexey Yarkov, 2016-10-30 11:28:10

How to assign a password to a user without my participation?

I am writing a script to install the necessary software on the server. And when installing vsftpd, you need to create a user. Now there is this code:

apt-get update
apt-get install -y vsftpd
useradd -m sftpuser -s /usr/sbin/nologin
passwd sftpuser

How can I passwd sftpuser without entering a password? That is, you need to set the sftpuser password , but without entering it manually, but for example, write it in a script or read it from a file.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Yarkov, 2016-10-30
@yarkov

Google is our everything)))))

FTPUSER="sftpuser"
useradd -m $FTPUSER -s /usr/sbin/nologin
echo "$FTPUSER\n$FTPUSER\n" > ~/$FTPUSER
passwd $FTPUSER < ~/$FTPUSER
rm -f ~/$FTPUSER

S
shuraosipov, 2016-10-30
@shuraosipov

You can also do this:
echo password123 | passwd --stdin username

1
15432, 2016-10-30
@15432

echo "secret_pass:sftpuser" | chpasswd

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question