我想使用一个脚本来快速将用户添加到我的 ftp 服务器,我认为这可行:
#!/bin/sh
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${RED}2020 Maraton Consulting${NC} script for adding FTP-users"
echo "Does the server have active FTP-connections?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "this script will restart the ftp-server, come back when there are no active
connections"; exit;;
No ) echo "continue"; break;;
esac
done
echo "This script will restart the server, abort in case of active ftp connections"
echo 'Welcome to this script to add a user to the ftp server'
echo "Please state a username:"
read USERNAME
echo "Please state a password:"
read PASSWORD
sudo adduser --disabled-password --gecos $USERNAME --force-badname
echo $USERNAME:$PASSWORD | chpasswd
sudo mkdir /home/$USERNAME/ftp
sudo chown nobody:nogroup /home/$USERNAME/ftp
sudo chmod a-w /home/$USERNAME/ftp
sudo mkdir /home/$USERNAME/ftp/files
sudo chown $USERNAME:$USERNAME /home/$USERNAME/ftp/files
echo "$USERNAME" | sudo tee -a /etc/vsftpd.userlist
sudo systemctl restart vsftpd
echo "the user can use the ftp-server with the following credentials"
echo -e "host:${RED} XXX.XXX.XXX.XX ${NC}"
echo -e "protocol:${RED} FTP-File Transfer Protocol ${NC}"
echo -e "encryption: ${RED}Require explicit FTP over TLS ${NC}"
echo -e "Logon Type: ${RED}Ask for password${NC}"
echo -e "User:${RED} $USERNAME ${NC}"
echo -e "use password when prompted:${RED} $PASSWORD ${NC}"
echo -e "Maraton Consulting wishes you a nice day"
但是 adduser 似乎有问题。
这是我收到的响应,我不知道我做错了什么。
thecaptain@maraton-node-alpha:~/scripts$ bash add-ftp-user.sh
2020 Maraton Consulting script for adding FTP-users
Does the server have active FTP-connections?
1) Yes
2) No
#? 2
continue
Welcome to this script to add a user to the ftp server
Please state a username:
testuser
Please state a password:
testpassword
adduser: Only one or two names allowed.
chpasswd: (user testuser) pam_chauthtok() failed, error:
Authentication token manipulation error
chpasswd: (line 1, user testuser) password not changed
mkdir: cannot create directory ‘/home/testuser/ftp’: No such file or directory
chown: cannot access '/home/testuser/ftp': No such file or directory
chmod: cannot access '/home/testuser/ftp': No such file or directory
mkdir: cannot create directory ‘/home/testuser/ftp/files’: No such file or directory
chown: invalid user: ‘testuser:testuser’
testuser
the user can use the ftp-server with the following credentials
host: xxx.xxx.xxx.xx
protocol: FTP-File Transfer Protocol
encryption: Require explicit FTP over TLS
Logon Type: Ask for password
User: testuser
use password when prompted: testpassword
Maraton Consulting wishes you a nice day