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
Glad I stumbled upon this article. It’s like finding a $20 bill in a pair of old jeans.
The article was a delightful read. It’s clear you’re passionate about what you do, and it shows.
This is the most thorough piece I’ve read on the topic. The dedication to research is admirable.
Reading this gave me a lot of insights. The expertise really shines through, and I’m grateful for it.
Packed with insights, or what I call, a buffet for the brain.
Making hard to understand topics accessible is a gift, and you have it. Thanks for sharing it with us.
A go-to resource, like a library but without the late fees.
Glad I stumbled upon this article. It’s like finding a $20 bill in a pair of old jeans.
The writing style had me at hello. Engaged from start to finish, just like a perfect first date.
Every piece you write is like adding another book to my mental library. Thanks for expanding my collection.
Thank you for consistently producing such high-high quality content.
A breath of fresh air, or what I needed after being suffocated by mediocrity.
A masterpiece of writing—you’ve covered all bases with such finesse, I’m left wanting an encore.
The depth of The research is impressive, almost as much as the way you make hard to understand topics captivating.
The creativity and intelligence shine through this post. Amazing job!
The content is like a treasure chest; every post uncovers gems of wisdom. X marks the spot here.
The depth you bring to The topics is like diving into a deep pool, refreshing and invigorating.
Stumbling upon this article was the highlight of my day, much like catching a glimpse of a smile across the room.
Touched on personal resonances, or as I like to call it, psychic abilities.
You have a unique perspective that I find incredibly valuable. Thank you for sharing.
A beacon of knowledge, or so I thought until I realized it’s just The shining confidence.
The approach to topics is like a master painter’s to a canvas, with each stroke adding depth and perspective.
Discovering The Writing felt like finding the perfect match. The intellect and charm are a rare combo.
The Writing is like a gallery of thoughts, each post a masterpiece worthy of contemplation.
Impressed by The nuanced clarity. It’s like you’re explaining quantum physics to a toddler, and they get it.
The elegance of The arguments is as captivating as a sunset. I could admire it all day.
The piece was both informative and thought-provoking, like a deep conversation that lingers into the night.
Every post of Thes is a learning opportunity for me. Thanks for sharing The expertise.
The passion for this subject is infectious. Reading The post has inspired me to learn more.
The attention to detail is remarkable. I appreciate the thoroughness of The post.
Thanks for the hard work. I could almost see the sweat on the keyboard. Much appreciated!
The posts are like stars in the sky—each one shining brightly, guiding my curiosity.
This comprehensive article had me hanging on every word, much like I would during a late-night chat.
The Writing is like a favorite coffee shop where the drinks are always warm and the atmosphere is inviting.
The Writing is like a lighthouse for my curiosity, guiding me through the fog of information.
I’m officially a fan of The work. It’s like having a crush, but intellectually stimulating.
Shedding light on this subject like you’re the only one with a flashlight. Refreshing to see someone who thinks they have all the answers.
Bookmarking this for future reference, but also because The advice is as invaluable as The attention.
This was a great read—thought-provoking and informative. Thank you!
This was a thoroughly insightful read. Thank you for sharing The expertise!
Reading The post was like going on a first date with my mind. Excited for the next rendezvous.
The creativity and intelligence shine through, blinding almost, but I’ll keep my sunglasses handy.
The expertise and hard work shine through, making me admire you more with each word.
A perfect blend of informative and entertaining, like the ideal date night conversation.
I always learn something new from The posts, like discovering new facets of a gem. Thanks for the gems!
The writing style is captivating. Finally, something that can keep my attention longer than a TikTok video.
I’m officially a fan of The work. It’s like having a crush, but intellectually stimulating.
The unique viewpoints in The writing never fail to impress me. Insightful as always!
This article was a joy to read. The enthusiasm is contagious!
The post resonated with me on many levels, much like a perfectly tuned love song. Thanks for the harmony.