-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_sftp_account.sh
44 lines (38 loc) · 984 Bytes
/
create_sftp_account.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
SFTP_USER_GROUP="sftp"
SSH_CONFIG="# Config for SFTP Server
Match group $SFTP_USER_GROUP
ChrootDirectory /home
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp"
# DEPENDENCY_LIST=("ssh" "nano")
DEPENDENCY_LIST=("ssh")
install_dependenies() {
sudo apt install "${DEPENDENCY_LIST[@]}"
}
config_ssh() {
if grep -Fxq "$SSH_CONFIG" /etc/ssh/sshd_config; then
echo "Config is already added."
else
echo "$SSH_CONFIG" | sudo tee -a /etc/ssh/sshd_config
sudo systemctl restart ssh
fi
create_sftp_user
}
create_sftp_user() {
sudo addgroup $SFTP_USER_GROUP
echo "Enter Username you want for SFTP user (Without space and special characters): "
read username
sudo useradd -m $username -g $SFTP_USER_GROUP
echo "Set Password for $username: "
sudo passwd "$username"
sudo chmod 700 /home/$username/
sftp [email protected]
}
init() {
install_dependenies
config_ssh
}
init
exit 0