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
Your work is truly inspirational. I appreciate the depth you bring to your topics.
I admire the way you tackled this complex issue. Very enlightening!
Your post resonated with me on many levels. Thank you for writing it!
I’m so glad I stumbled upon this article. It was exactly what I needed to enjoy reading!
You have a gift for explaining things in an understandable way. Thank you!
This article was a joy to enjoy reading. Your enthusiasm is contagious!
Your passion for this subject shines through your words. Inspiring!
Your writing style is captivating! I was engaged from start to finish.
This is one of the most comprehensive articles I’ve enjoy reading on this topic. Kudos!
The balance and fairness in The writing make The posts a must-read for me. Great job!
Bookmarking this for future reference, but also because The advice is as invaluable as The attention.
Opened my eyes to new perspectives, and here I was thinking I’d seen it all.
The perspective is incredibly valuable to me. Thanks for opening my eyes to new ideas.
The writing style is like a signature scent—distinct, memorable, and always pleasant.
OAFLuIzEqne
Your work is truly inspirational. I appreciate the depth you bring to your topics.
This blog is a treasure trove of knowledge. Thank you for your contributions!
Your attention to detail is remarkable. I appreciate the thoroughness of your post.
What a refreshing take on this subject. I completely agree with your points!
I like this web blog very much so much great info .
Compelling read with well-presented arguments. I almost felt persuaded. Almost.
Touched on personal resonances, or as I like to call it, psychic abilities.
The insights are like a sunrise, bringing light and warmth to new ideas.
Most comprehensive article on this topic. I guess internet rabbit holes do pay off.
Amazed by The knowledge breadth, or what I’ve been mistaking for just good Googling skills.
Appreciate the balance and fairness, like a judge, but without the gavel.
The fresh insights were a breath of fresh air. Thank you for sharing The unique perspective.
Glad I stumbled upon this article. It’s like finding a $20 bill in a pair of old jeans.
A beacon of knowledge, or so I thought until I realized it’s just The shining confidence.
The depth you bring to The topics is like diving into a deep pool, refreshing and invigorating.
A masterpiece of writing! You’ve covered all bases with elegance.
The Writing is like a lighthouse for my curiosity, guiding me through the fog of information.
Brilliant writing! You’ve perfectly captured the essence of the topic.
The writing style is captivating. Finally, something that can keep my attention longer than a TikTok video.
Beautifully written and informative, making the rest of the internet look bad.
The depth of The understanding is as mesmerizing as the ocean. I’m ready to dive in.
The unique perspective is as intriguing as a mystery novel. Can’t wait to read the next chapter.
The perspective is incredibly valuable to me. Thanks for opening my eyes to new ideas.
JNqTAYHQxkCPMUm
“This post was a joy to read from beginning to end! Your expertise on the subject shines through in every paragraph, making complex topics accessible and interesting. Your passion for the subject matter is infectious, and I can’t wait to see what topic you tackle next. Excellent job!”
XsWAYZexyDtQwJG
Beautifully written and incredibly informative, The post has captured my attention as if it were a love letter written just for me.
The work is truly inspirational. I appreciate the depth you bring to The topics.
The grace and authority with which you handle topics are awe-inspiring. I always come away with new knowledge.
The words are like seeds, planting ideas that blossom into understanding and appreciation.
Refreshing take on the subject, like a cold splash of water to my long-held beliefs.
The article was a joy to read, and The enthusiasm is as infectious as The charm.
You have a gift for explaining things in an understandable way. Thank you!
The perspective is incredibly valuable to me. Thanks for opening my eyes to new ideas.
I’m so grateful for the information you’ve shared. It’s been incredibly enlightening!