mirror of
https://github.com/myvesta/vesta
synced 2025-08-14 18:49:21 -07:00
Jailed SFTP via OpenSSH
This commit is contained in:
parent
f451b8a99a
commit
93b2a8617a
8 changed files with 344 additions and 0 deletions
66
bin/v-add-user-sftp-jail
Executable file
66
bin/v-add-user-sftp-jail
Executable file
|
@ -0,0 +1,66 @@
|
|||
#!/bin/bash
|
||||
# info: add user sftp jail
|
||||
# opions: USER
|
||||
#
|
||||
# The script enables sftp jailed environment
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Variable&Function #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Argument defenition
|
||||
user=$1
|
||||
|
||||
# Includes
|
||||
source $VESTA/func/main.sh
|
||||
source $VESTA/conf/vesta.conf
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '1' "$#" 'USER'
|
||||
validate_format 'user'
|
||||
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
|
||||
if [ -z "$(mount |grep $home)" ]; then
|
||||
mount -o bind $home /chroot/$user/$home/
|
||||
fi
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Logging
|
||||
#log_event "$OK" "$EVENT"
|
||||
|
||||
exit
|
Loading…
Add table
Add a link
Reference in a new issue