Let’s say you need a handful of users for testing out multiple SFTP accounts. Additionally, you do not want the users to be able to login via SSH and you want everything else about the users to be identical (ie, password, content of home directory, etc).
The following script will create 10 such users:
#!/bin/bash
for i in {1..10};
do
USER=test_t
USER+=$i
USER+=_1_1
echo $USER
GROUP=sftpusers
echo $GROUP
egrep "^$USER" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "WARNING: [$USER] already exists"
continue
fi
PASSWORD_=Password123!
PASSWORD_=$(perl -e 'print crypt($ARGV[0], "salty")' $PASSWORD_)
echo $PASSWORD_
adduser -p $PASSWORD_ $USER
usermod -g $GROUP $USER
usermod -s /bin/nologin $USER
chown root:$USER /home/$USER
chmod 755 /home/$USER
mkdir /home/$USER/writable
chown $USER:$GROUP /home/$USER/writable
chmod ug+rwX /home/$USER/writable
done;
When we execute, we will see the following output
# ./create-sftp-user.sh
test_t1_1_1
sftpusers
saMNhdbYqwtng
test_t2_1_1
sftpusers
saMNhdbYqwtng
test_t3_1_1
sftpusers
saMNhdbYqwtng
test_t4_1_1
sftpusers
saMNhdbYqwtng
test_t5_1_1
sftpusers
saMNhdbYqwtng
test_t6_1_1
sftpusers
saMNhdbYqwtng
test_t7_1_1
sftpusers
saMNhdbYqwtng
test_t8_1_1
sftpusers
saMNhdbYqwtng
test_t9_1_1
sftpusers
saMNhdbYqwtng
test_t10_1_1
sftpusers
saMNhdbYqwtng
We can confirm the users were created like so:
# cat /etc/passwd
...
test_t1_1_1:x:1002:1001::/home/test_t1_1_1:/bin/nologin
test_t2_1_1:x:1003:1001::/home/test_t2_1_1:/bin/nologin
test_t3_1_1:x:1004:1001::/home/test_t3_1_1:/bin/nologin
test_t4_1_1:x:1005:1001::/home/test_t4_1_1:/bin/nologin
test_t5_1_1:x:1006:1001::/home/test_t5_1_1:/bin/nologin
test_t6_1_1:x:1007:1001::/home/test_t6_1_1:/bin/nologin
test_t7_1_1:x:1008:1001::/home/test_t7_1_1:/bin/nologin
test_t8_1_1:x:1009:1001::/home/test_t8_1_1:/bin/nologin
test_t9_1_1:x:1010:1001::/home/test_t9_1_1:/bin/nologin
test_t10_1_1:x:1011:1001::/home/test_t10_1_1:/bin/nologin
Happy testing!
Resources:
- https://www.developerfiles.com/how-to-create-sftp-access-to-a-single-folder-on-linux/#:~:text=%20How%20to%20create%20SFTP%20access%20to%20a,on%20%E2%80%9C%20ChrootDirectory%20%E2%80%9D%20will%20be…%20More%20
- https://www.cyberciti.biz/tips/howto-write-shell-script-to-add-user.html
Explaining things in an understandable way is a skill, and you’ve mastered it on the topic of the state of the country. Thanks for clearing things up for me.
Discovering The Writing felt like finding the perfect match. The intellect and charm are a rare combo.
I appreciate the unique viewpoints you bring to the writing on the state of the country. Very insightful!
The unique viewpoints in the writing on the state of the country never fail to impress me. Insightful as always!
Thank you for consistently producing such high-high quality content on the state of the country.
The piece was both informative and thought-provoking, like a deep conversation that lingers into the night.
The Writing is a constant source of inspiration and knowledge. Thank you!
The insights on the state of the country add so much value to the conversation. I always learn something new from you.
What a refreshing take on the state of the country. I completely agree with the points!
This post was a breath of fresh air, like a surprise message that brightens The day. Thank you for the lift.
The elegance of The prose is like a fine dance, each word stepping gracefully to the next.
I admire the way you tackled this hard to understand issue. Very enlightening!
I admire the way you tackled this hard to understand issue. Very enlightening!
The work is both informative and thought-provoking on the state of the country. I’m really impressed by the high quality of the content.
The ability to convey hard to understand ideas so effortlessly is as attractive as a perfectly tailored suit.
The creativity and insight left a big impression on me. Fantastic job!
Incredibly informative post! I learned a lot and look forward to more.
This post is a testament to The expertise and hard work. Thank you!
The writing style is like a signature scent—distinct, memorable, and always pleasant.
Making hard to understand topics accessible, you’re like the translator I never knew I needed.
Compelling read with well-presented arguments. I almost felt persuaded. Almost.
Impressed by The nuanced clarity. It’s like you’re explaining quantum physics to a toddler, and they get it.
Reading The work is like watching the sunrise, a daily reminder of beauty and new beginnings.
Making hard to understand topics accessible, you’re like the translator I never knew I needed.
The post was a beacon of knowledge, lighting up my day as if you knew just what I needed to hear.
This post was a breath of fresh air. Thank you for The unique insights!
The insights are like a sunrise, bringing light and warmth to new ideas.
Every article you write is like a new adventure. I’m always excited to see where you’ll take me next.
The fresh insights were a breath of fresh air. Thank you for sharing The unique perspective.
Charlotte Dog Park’s open space lets my dog run free, and I love watching him in his element.
The freedom my dog has at Charlotte Dog Park is everything—he’s a different dog off-leash.