Skip to content

Instantly share code, notes, and snippets.

@nicolas-brousse
Last active December 10, 2015 23:39
Show Gist options
  • Save nicolas-brousse/4511290 to your computer and use it in GitHub Desktop.
Save nicolas-brousse/4511290 to your computer and use it in GitHub Desktop.
Tips for a fresh install on Ubuntu server

Common installation and configuration (Ubuntu)

Do this operation with root user.

Apt-get

$ apt-get install vim
$ apt-get install wget
$ apt-get install git
$ apt-get install backup-manager
$ apt-get install fail2ban

SMTP server

If you have application that want to send mail follow this else go next.

sudo dpkg-reconfigure postfix

And enter this informations step by step:

Internet Site
NONE
server1.exemple.com
server1.exemple.com, localhost.exemple.com, localhost
No
127.0.0.0/8
0
+

Configure Backup manager

To configure backup manager vi /etc/backup-manager.conf

BM_ARCHIVE_METHOD: add mysql (and svn if you have svn installed)
BM_TARBALL_DIRECTORIES: list of directories to backup (separated by space)
BM_TARBALL_BLACKLIST: list of ignored directories to backup (separated by space)

BM_UPLOAD: upload to remote server/ftp

BM_UPLOAD_METHOD = "ftp"
BM_UPLOAD_FTP_USER = "ftp_user"
BM_UPLOAD_FTP_PASSWORD = "ftp_password"
BM_UPLOAD_FTP_HOSTS = "fpt.host.tld"
BM_UPLOAD_FTP_PURGE = "true"
BM_UPLOAD_FTP_TTL = "2" (One more is used during the archives trasfert)
BM_UPLOAD_FTP_DESTINATION = "/" (Do not leave blank)

Crontab configuration

$ cp /usr/share/backup-manager/backup-manager.cron.tpl /etc/cron.daily/backup-manager
$ chmod a+x /etc/cron.daily/backup-manager

Crontab

Use file /etc/crontabor add file into /etc/cron.d/.

SSH

Disable ssh connection for root user and enable just for precise users or group.

Fresh install PHP PROD server (Ubuntu)

See common installation and configuration before
Do this operation with root user.

Apt-get

$ apt-get install mysql-server
$ apt-get install libapache2-mod-php5
$ apt-get install php-apc php5-cli php5-curl php5-dev php5-gd php5-imagick php5-intl php5-mcrypt php5-xsl

Fresh install RUBY/RAILS PROD server (Ubuntu)

See common installation and configuration before
Do this operation with root user.

Apt-get

$ apt-get install postgresql
$ apt-get isntall nginx

Backup-manager configurations for PostgreSQL

http://tcweb.org/wiki/Backup-manager_et_debian#Postgresql

RVM

Create user and group:

$ adduser
  --system \
  --disabled-password \
  --group \
  --shell /bin/sh \
  --gecos 'RVM' \
  --home /home/rvm \
  rvm

See http://rvm.io. (install into a ruby or rails unix user).
Add install the rvm requirments for ubuntu.

Define a ruby version as default.

$ rvm use x.x.x --default

Update rubygems?

$ rvm rubygems current

Passenger

Nginx

Other

For a better configuration you can create a user by application:

$ adduser app_user
$ adduser app_user rvm

Interesting Gist: https://gist.github.com/2499900.

Pure-FTPD configuration

Others commands

List crontab content of all user:
for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done

DNS

  • dig domain.tld
  • dig -x XXX.XXX.XXX.XXX: domain reverse

Network

  • netstat -atnpu: port stats

Mysql

  • mysqldump -u root --password="password" --all-databases | gzip> all_databases_dump.sql.gz: Dump all Mysql databases
  • mysql < dump.sql: Resore databases from a sql file
  • mysql database_name < dump.sql: Resore a database from a sql file

Users/groups

  • adduser --groups group_name user_name: Create user
  • adduser --system --no-create-home [--disabled-password] [--disabled-login] [--shell /bin/bash] --home-dir / --groups group_name user_name: Create system user
  • adduser group_name user_name: Add a user into a group

Get data from an other server

Run this command from on new server.
ssh remote.srv.tld "cd /data/;tar zcf - files" | tar zxf -
This command recursively copies /data/files from remote.srv.tld to local server a lot faster on slow network.

Source

Others

  • du -hs /path/to/folder: Get folder size

  • df -h: Get disks size

  • iptables -L -n -v

  • su user_name -c 'command to execute': execute a command with user_name user

  • find . -name ".svn" -exec rm -rf {} \;: remove .svn directories

  • tar cfz archive.tar.gz target_dir_or_file: archive and compress file or directory into tar.gz

Tools

  • rkhuntuer: root kit hunter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment