1
0
mirror of https://github.com/serghey-rodin/vesta.git synced 2025-03-11 20:26:30 -07:00
vesta/bin/v-add-user-sftp-jail

67 lines
1.6 KiB
Plaintext
Raw Normal View History

2015-09-18 17:42:48 +03:00
#!/bin/bash
# info: add user sftp jail
2015-11-06 17:38:58 +02:00
# options: USER
2015-09-18 17:42:48 +03:00
#
# The script enables sftp jailed environment
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
2015-11-06 17:38:58 +02:00
# Argument definition
2015-09-18 17:42:48 +03:00
user=$1
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'USER'
2016-06-09 17:04:18 +03:00
is_format_valid 'user'
2015-09-18 17:42:48 +03:00
if [ -z "$SFTPJAIL_KEY" ]; then
exit
fi
user_str=$(grep "^$user:" /etc/passwd |egrep "rssh|nologin")
if [ -z "$user_str" ]; then
exit
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining user homedir
home="$(echo $user_str |cut -f 6 -d :)"
# Adding chroot directory
if [ ! -d "/chroot/$user/$home" ]; then
mkdir -p /chroot/$user/$home
chmod 750 /chroot/$user
chmod 775 /chroot/$user/$home
chown root:sftp-only /chroot/$user
chown $user:sftp-only /chroot/$user/$home
fi
# Adding user to sftp group
usermod -a -G sftp-only $user
# Mouting home directory
2016-06-09 17:04:18 +03:00
if [ -z "$(mount |grep /chroot/$user/$home)" ]; then
2015-09-18 17:42:48 +03:00
mount -o bind $home /chroot/$user/$home/
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
2016-06-09 17:04:18 +03:00
log_event "$OK" "$ARGUMENTS"
2015-09-18 17:42:48 +03:00
exit