This is the first time I had to configure an Unix Server as a remote server for a website based on LAMP. It also need to offer SFTP and GIT support. I read a lot of guides and I wrote down all the steps those I did.
It is working right now. I would like to ask you if there are any security issues in my workflow or how can I improve the security of the system.
Let's start:
On my server there is a user "root
" and a user "dev
". dev
should be able to log-in on the server with sftp, upload and download files to /var/www/html
folder. His home folder is /var/www/
and it is chrooted jailed to that folder (I hope!). He does not have write access to /var/www/
but only to /html
folder.
This is what I did:
############ LAMP
useradd --home-dir /var/www -g www-data dev
chown -R dev:www-data /var/www/html && chmod 755 /var/www/html
apt-get install apache2
apt-get install mysql-server php5-mysql
mysql_install_db
mysql_secure_installation
apt-get install php5 libapache2-mod-php5 php5-mcrypt
apt-get install phpmyadmin apache2-utils
nano /etc/apache2/apache2.conf
(add Include /etc/phpmyadmin/apache.conf
change AllowOverride to All on /var/www/html/)
a2enmod rewrite
apt-get install php5-gd php5-curl php5-xmlrpc php5-pspell
service apache2 restart
nano /etc/phpmyadmin/apache.conf
(add AllowOverride All inside <Directory /usr/share/phpmyadmin>)
nano /usr/share/phpmyadmin/.htaccess
(add AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/apache2/.phpmyadmin.htpasswd
Require valid-user)
htpasswd -c /etc/apache2/.phpmyadmin.htpasswd dev
service apache2 restart
############ PHP EMAILS
apt-get install ssmtp
nano /etc/ssmtp/ssmtp.conf
(delete all and replace with (gmail example):
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
AuthUser=<YOUR-EMAIL>@gmail.com
AuthPass=<YOUR-PASSWORD>
FromLineOverride=YES)
############ FTP WITH SSH
apt-get install vsftpd
apt-get install openssh-server
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout /etc/ssl/private/vsftpd.pem -out /etc/ssl/private/vsftpd.pem
nano /etc/vsftpd.conf
(local_enable=YES
write_enable=YES
local_umask=022
chroot_local_user=YES
rsa_cert_file=/etc/ssl/private/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.pem
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
require_ssl_reuse=NO
ssl_ciphers=HIGH)
nano /etc/ssh/sshd_config
(Match group www-data <-- with this I can a broken pipe error on ssh connection
ChrootDirectory /var/www
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
PasswordAuthentication yes)
etc/init.d/vsftp restart
############ GIT
apt-get install git
git config --global user.name "Name"
git config --global user.email email@email.com
mkdir /var/www/.shh && chown dev:dev /var/www/.ssh/ && chmod 700 /var/www/.ssh
su dev && ssh-keygen -t rsa -b 4096 -C "email@email.com"
(path: /var/www/.ssh/)
cd /var/www/git-repo-sever
git init --bare
Is this safe? Is this a good approach?