Skip to content

Instantly share code, notes, and snippets.

@disono
Last active August 20, 2018 21:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save disono/57800cecf7f26f3ed3bbc92deb483202 to your computer and use it in GitHub Desktop.
Save disono/57800cecf7f26f3ed3bbc92deb483202 to your computer and use it in GitHub Desktop.
Debian Server/Desktop Setup

Debian GNU/Linux Version 8.0 (Jessie)

Securing Server

https://www.digitalocean.com/community/tutorials/7-security-measures-to-protect-your-servers

For Debian

$ sudo nano /etc/apt/sources.list

// add this to file to
$ deb http://ftp.debian.org/debian jessie main
$ deb-src http://ftp.debian.org/debian jessie main

$ deb http://ftp.debian.org/debian jessie-updates main
$ deb-src http://ftp.debian.org/debian jessie-updates main

Networking

  • ip command: It is used to show or manipulate routing, devices, policy routing and tunnels.
  • netstat command: It is used to display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
  • ifconfig command: It is used to display or configure a network interface.
$ ip link show
  • lo: Loopback interface.
  • eth0: First Ethernet network interface.
  • wlan0: First Wireless network interface.
  • ppp0: First Point to Point Protocol network interface which can be used by dial up modem, PPTP vpn connection, or 3G wireless USB modem./li>
  • vboxnet0, vmnet1, vmnet8: Virtual machine interface working in bridge mode or NAT mode.
$ netstat -i

Add sudo

$ apt install sudo -y

$ adduser yourusername
$ usermod -aG sudo yourusername

// check if sudo is listed @
$ visudo

dotdeb

$ deb http://packages.dotdeb.org jessie all
$ deb-src http://packages.dotdeb.org jessie all

Multimedia (ffmpeg)

$ deb http://www.deb-multimedia.org/ wheezy main non-free

// or you can use
$ deb http://www.deb-multimedia.org jessie main non-free
$ deb-src http://www.deb-multimedia.org jessie main non-free

Allow apt to trust deb-multimedia key

$ apt-get install deb-multimedia-keyring

Install Nginx

$ sudo apt-get install nginx
$ ps aux | grep nginx
$ pgrep nginx

// Use the netstat command as follows to verify that port 80 is open
$ netstat -tulpn | grep :80

// To enable Nginx on boot run the following systemctl command
$ sudo systemctl enable nginx

// Restart Nginx
$ sudo systemctl restart nginx

// Stop nginx server command
$ sudo systemctl stop nginx

// Start nginx server command
$ sudo systemctl start nginx

// Find status of nginx server command
$ sudo systemctl status nginx

// Or find your public IP address using the ip command/ifconfig command
$ ip a
$ ifconfig eth0

// Configure Nginx web server
// By default all HTML/css/images files are stored in /var/www/html/ directory. 
// This is known as the root of your web server. It is defined in /etc/nginx/sites-enabled/default config file. 
// You can edit it with either vim command/nano command
$ sudo nano /etc/nginx/sites-enabled/default

// Header underscore add
underscores_in_headers on;

// The /etc/nginx/nginx.conf is your main nginx config file and /etc/nginx/sites-enabled/default is default config file.
$ sudo nano /etc/nginx/nginx.conf

// Creating your own config file
// First create a user named cbzwww for www.cyberciti.biz domain using the useradd command
$ sudo useradd -c "cyberciti.biz user" -d /home/nginx-www.cyberciti.biz -s /usr/sbin/nologin -m cbzwww

// To lock the password for the cbzwww account, enter:
$ sudo passwd -l cbzwww

// Verify it
$ ls -l /home/

// To create a Virtual Hosts named www.cyberciti.biz, enter;
$ sudo nano /etc/nginx/sites-available/www.cyberciti.biz.conf

// Append the basic config
server {
	listen 80;
	listen [::]:80;
 
	server_name www.cyberciti.biz;
 
	root /home/nginx-www.cyberciti.biz;
	index index.html;
 
	location / {
		try_files $uri $uri/ =404;
	}
}

// Save and close the file. You must create a soft link as follows
$ sudo ln -s /etc/nginx/sites-available/www.cyberciti.biz.conf /etc/nginx/sites-enabled/www.cyberciti.biz.conf

// Finally test and reload server
$ sudo nginx -t
$ sudo systemctl reload nginx

// Now create a test file at
// Save and close the file. Set correct permissions using chmod command and chown command:
$ sudo nano /home/nginx-www.cyberciti.biz/index.html
$ sudo chown cbzwww:cbzwww /home/nginx-www.cyberciti.biz/index.html
$ sudo chmod 0444 /home/nginx-www.cyberciti.biz/index.html
$ ls -l /home/nginx-www.cyberciti.biz/index.html

PHPMyAdmin for Nginx

Install add-apt-repository

$ sudo apt-get install software-properties-common

Remove PHP

For PHP 7.2 refers to this link.

$ sudo apt-get purge php.*

Install PHP 7.*

Reference

If dotdeb failed

// fetch and install GnuPG key
$ wget https://www.dotdeb.org/dotdeb.gpg
$ sudo apt-key add dotdeb.gpg

Or add this to gpg

$ gpg --keyserver keys.gnupg.net --recv-key 89DF5277
$ gpg -a --export 89DF5277 | sudo apt-key add -

Install sudo

$ apt-get install sudo
$ nano /etc/sudoers
add line user ALL=(ALL) ALL

Update the packages

$ apt-get clean
$ apt-get update
$ apt-get upgrade

If ffmpeg is installed uninstall

$ apt-get remove ffmpeg

Install libraries

$ apt-get install build-essential libmp3lame-dev libvorbis-dev libtheora-dev libspeex-dev yasm pkg-config libfaac-dev libopenjpeg-dev libx264-dev

Install MongoDB

https://www.globo.tech/learning-center/install-mongodb-debian-9

Install Apache

$ apt-get install apache2

How to find your server's IP address

// you can run the following command to reveal your VPS's IP address
$ ifconfig eth0 | grep inet | awk '{ print $2 }'

Install MySQL

$ apt-get install mysql-server

Reset MySQL "root" Password

Reference

Finish the installation by running

$ mysql_secure_installation
    - Remove anonymous users? [Y/n] y    
    - Disallow root login remotely? [Y/n] y
    - Remove test database and access to it? [Y/n] y
    - Reload privilege tables now? [Y/n] y

Intall PHP

$ apt-get install php7-* php-pear
$ apt-get install php-mysql
$ sudo apt-get install snmp
$ sudo systemctl restart apache2

Test the installation

$ nano /var/www/info.php
  <?php phpinfo(); ?>

Install PHPMyAdmin

$ sudo apt-get install phpmyadmin
$ sudo nano /etc/apache2/apache2.conf

Add to config file

Include /etc/phpmyadmin/apache.conf
$ sudo systemctl restart apache2

Permissions

$ chown -R www-data:www-data /path/to/www/application-folder
$ chmod -R g+rw /path/to/www
$ chmod -R 755 /path/to/www

www permissions

$ sudo groupadd www
$ sudo usermod -a -G www ec2-user

Restart / logout

$ sudo chown -R root:www /var/www
$ sudo chmod 2775 /var/www
$ find /var/www -type d -exec sudo chmod 2775 {} +
$ find /var/www -type f -exec sudo chmod 0664 {} +

Install ffmpeg

$ apt-get install deb-multimedia-keyring
$ apt-get install libav-tools
$ apt-get install ffmpeg

Install ffmpeg from SOURCE

https://www.assetbank.co.uk/support/documentation/install/ffmpeg-debian-squeeze/ffmpeg-debian-jessie

$ mkdir software
$ cd software
$ wget http://ffmpeg.org/releases/ffmpeg-2.7.2.tar.bz2
$ cd ..
$ mkdir src
$ cd src
$ tar xvjf ../software/ffmpeg-2.7.2.tar.bz2

Move into the source directory

$ cd ffmpeg-2.7.2

Configure and install

$ ./configure --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libx264 --enable-libspeex --enable-shared --enable-pthreads --enable-libopenjpeg --enable-libfaac --enable-nonfree
$ make
$  make install

Run "/sbin/ldconfig" as root.

Install composer

$ cd /tmp/
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
$ sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
$ composer --version

Multiple php version

// disable
$ sudo a2dismod php5

// enable
$ sudo a2enmod php7.0

// restart apache

FTP installation

// install
$ apt install vsftpd ftp

// configure
$ nano /etc/vsftpd.conf

// add this configuration
listen=NO
listen_ipv6=YES
anonymous_enable=NO
local_enable=YES
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO
write_enable=YES
pam_service_name=ftp
allow_writeable_chroot=YES

// optional configuration
userlist_file=/etc/vsftpd.userlist
userlist_enable=YES

// restart
$ systemctl restart vsftpd

// add ftp user
$ adduser {username}

// change the user directory to /var/www
$ usermod --home /var/www/ {username}

// permissions
$ chmod a-w /var/www

Install PHPMyAdmin

For Debian 9 follow the steps below:

https://www.server-world.info/en/note?os=Debian_9&p=mariadb&f=2

$ apt install php-mcrypt
$ systemctl restart apache2
$ apt install phpmyadmin

// force phpMyAdmin to use SSL
// edit the config
$ nano /etc/phpmyadmin/config.inc.php
// update or edit
// $cfg['ForceSSL'] = 'true';

$ systemctl restart apache2

$ mysql -u root -p

// create new admin user for phpmyadmin
// CREATE USER 'your-username'@'localhost' IDENTIFIED BY 'your-password';
// GRANT ALL PRIVILEGES ON *.* TO 'your-username'@'localhost';
// FLUSH PRIVILEGES;

// folder permissions
$ chown -R {username} /var/www/html
$ chmod 757 -R /var/www/html

Configure Apache and hosting website

https://www.linode.com/docs/websites/hosting-a-website

Create SSH Keys

https://www.linode.com/docs/security/use-public-key-authentication-with-ssh

Setup for Fail2Ban

https://www.vultr.com/docs/how-to-setup-fail2ban-on-debian-9-stretch

Setup you own mail server (NOT RECOMMENDED)

https://thomas-leister.de/en/mailserver-debian-stretch

Install Squaremail

https://www.linode.com/docs/email/clients/install-squirrelmail-on-ubuntu-16-04-or-debian-8

Install NodeJS

https://www.linode.com/docs/development/nodejs/how-to-install-nodejs-and-nginx-on-debian

Add secondary ip-4

https://www.vultr.com/docs/add-secondary-ipv4-address

Scan using ClamAV

https://www.linode.com/docs/security/scanning-your-linode-for-malware

Scan using rkhunter

https://www.upcloud.com/support/scanning-debian-8-0-server-for-malware

https://www.clamav.net

Resources

https://linuxconfig.org/how-to-install-a-lamp-server-on-debian-9-stretch-linux

https://linuxhostsupport.com/blog/how-to-install-wordpress-with-php-7-1-and-nginx-on-a-debian-9-vps

https://www.digitalocean.com/community/tutorials/how-to-set-up-vsftpd-for-a-user-s-directory-on-ubuntu-16-04

https://www.benscobie.com/fixing-500-oops-vsftpd-refusing-to-run-with-writable-root-inside-chroot

https://www.digitalocean.com/community/tutorials/how-to-configure-vsftpd-to-use-ssl-tls-on-an-ubuntu-vps

https://linuxconfig.org/how-to-configure-ftp-server-on-debian-9-stretch-linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment