Skip to content

Commit

Permalink
Safer sshd_config update. Check for site directory existance
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplate committed May 8, 2012
1 parent 48349de commit 031607c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
4 changes: 4 additions & 0 deletions nginx-add-php.sh
Expand Up @@ -59,6 +59,10 @@ EOF
fi

# Create destination directories
if [ -d "$DESTDIR" ]; then
echo "Site directory $DESTDIR already exists. Script will not continue."
exit 1
fi
mkdir -p "$DESTDIR/public"
mkdir "$DESTDIR/logs"

Expand Down
4 changes: 4 additions & 0 deletions nginx-add-ruby.sh
Expand Up @@ -42,6 +42,10 @@ else
fi

# Create destination directories
if [ -d "$DESTDIR" ]; then
echo "Site directory $DESTDIR already exists. Script will not continue."
exit 1
fi
mkdir -p "$DESTDIR/public"
mkdir "$DESTDIR/views"
mkdir "$DESTDIR/tmp"
Expand Down
29 changes: 23 additions & 6 deletions nginx-common.sh
Expand Up @@ -25,15 +25,28 @@ function prepare_user {
cat /etc/group | grep sftp > /dev/null
if [ $? -ne 0 ]; then
addgroup sftp > /dev/null
grep 'Match Group sftp' /etc/ssh/sshd_config
fi
usermod -a -G sftp $user_name

# Does ssh configuration has a sftp section?
grep -q 'Match Group sftp' /etc/ssh/sshd_config
if [ $? -ne 0 ]; then
cp /etc/ssh/sshd_config tmp/sshd_config.backup
echo '' >> /etc/ssh/sshd_config
echo 'Match Group sftp' >> /etc/ssh/sshd_config
echo ' ChrootDirectory %h' >> /etc/ssh/sshd_config
echo ' ForceCommand internal-sftp -f AUTH -l INFO' >> /etc/ssh/sshd_config
echo ' AllowTcpForwarding no' >> /etc/ssh/sshd_config
sshd -t
if [ $? -ne 0 ]; then
echo 'Match Group sftp' >> /etc/ssh/sshd_config
echo ' ChrootDirectory %h' >> /etc/ssh/sshd_config
echo ' ForceCommand internal-sftp -f AUTH -l INFO' >> /etc/ssh/sshd_config
echo ' AllowTcpForwarding no' >> /etc/ssh/sshd_config
cp tmp/sshd_config.backup /etc/ssh/sshd_config
echo 'SSH reported error in configuration file after change. Previous config is restored.'
echo 'Fix configuration file /etc/ssh/sshd_config manually. The script is continuing.'
else
rm tmp/sshd_config.backup
restart ssh
fi
fi
usermod -a -G sftp $user_name

# Set up for logging sftp operations for this user
if [ ! -f /etc/rsyslog.d/sftp.conf ]; then
Expand All @@ -42,6 +55,10 @@ function prepare_user {
fi
sed -i "/sftp.log/i \$AddUnixListenSocket $HOMEDIR/dev/log" /etc/rsyslog.d/sftp.conf
restart rsyslog
if [ $? -ne 0 ]; then
echo 'Failed to restart rsyslog'
exit $?
fi
}


Expand Down

0 comments on commit 031607c

Please sign in to comment.