All Projects → chhantyal → 5minutes

chhantyal / 5minutes

Licence: bsd-3-clause
First 5 minutes on new servers. Secure your servers with single command - Ansible playbook

Projects that are alternatives of or similar to 5minutes

Automate With Ansible
《現代 IT 人一定要知道的 Ansible 自動化組態技巧》
Stars: ✭ 188 (+69.37%)
Mutual labels:  ansible, ubuntu, devops
Serverfarmer
Manage multiple servers with different operating systems, configurations, requirements etc. for many separate customers in an outsourcing model.
Stars: ✭ 122 (+9.91%)
Mutual labels:  ansible, ubuntu, devops
Ubuntu1604 Cis
Ubuntu CIS Hardening Ansible Role
Stars: ✭ 88 (-20.72%)
Mutual labels:  ansible, ubuntu
Learning Tools
A collection of tools and files for learning new technologies
Stars: ✭ 1,287 (+1059.46%)
Mutual labels:  ansible, ubuntu
Raspberry Pi Dramble
Raspberry Pi Kubernetes cluster that runs HA/HP Drupal 8
Stars: ✭ 1,317 (+1086.49%)
Mutual labels:  ansible, devops
Packer Ubuntu 1404
DEPRECATED - Packer Example - Ubuntu 14.04 Vagrant Box using Ansible provisioner
Stars: ✭ 81 (-27.03%)
Mutual labels:  ansible, ubuntu
Jjg Ansible Windows
[DEPRECATED] Windows shell provisioning script to bootstrap Ansible from within a Vagrant VM.
Stars: ✭ 82 (-26.13%)
Mutual labels:  ansible, devops
Ansible Interactive Tutorial
Interactive Ansible tutorials with dead simple setup via Docker
Stars: ✭ 1,309 (+1079.28%)
Mutual labels:  ansible, devops
Portable Ansible
Ansible without requirements to be installed (for pull-mode)
Stars: ✭ 75 (-32.43%)
Mutual labels:  ansible, devops
Packer Ubuntu 1804
This build has been moved - see README.md
Stars: ✭ 101 (-9.01%)
Mutual labels:  ansible, ubuntu
Vagrant Box Templates
Stars: ✭ 100 (-9.91%)
Mutual labels:  ansible, ubuntu
Polkadot Secure Validator
Polkadot Validator Secure Setup
Stars: ✭ 108 (-2.7%)
Mutual labels:  ansible, devops
Rocket.chat.ansible
Deploy Rocket.Chat with Ansible!
Stars: ✭ 80 (-27.93%)
Mutual labels:  ansible, ubuntu
Azure
Azure-related repository
Stars: ✭ 78 (-29.73%)
Mutual labels:  ansible, devops
Ansible Haproxy
Ansible role to set up (the latest version of) HAProxy in Ubuntu systems
Stars: ✭ 83 (-25.23%)
Mutual labels:  ansible, ubuntu
Ansible Nas
Build a full-featured home server or NAS replacement with an Ubuntu box and this playbook.
Stars: ✭ 1,198 (+979.28%)
Mutual labels:  ansible, ubuntu
Ansible Podman Collections
Repository for Ansible content that can include playbooks, roles, modules, and plugins for use with the Podman tool
Stars: ✭ 89 (-19.82%)
Mutual labels:  ansible, devops
Awx Ha Instancegroup
Build AWX clustering on Docker Standalone Installation
Stars: ✭ 106 (-4.5%)
Mutual labels:  ansible, devops
Ansible Playbook
Ansible playbook to deploy distributed technologies
Stars: ✭ 61 (-45.05%)
Mutual labels:  ansible, devops
Ubuntu Dev Machine Setup
Configure your Ubuntu 20.04 LTS and 20.10 Desktop
Stars: ✭ 63 (-43.24%)
Mutual labels:  ansible, ubuntu

5Minutes - Server Security Essentials

Secure your Linux server with single command!

A while back, I read this article about what you should do first when you get new server. Doing so manually is quite boring though, and error prone. So, I tried to automate with Ansible, and added few extra security features like completely disabling root and password login etc.

Install

So you have new servers with root access, please follow these steps.

  1. Install Ansible on your local computer. It's really easy if you have updated Python

sudo pip install ansible

  1. Clone this repo and change hosts file with IP address of your servers.

git clone [email protected]:chhantyal/5minutes.git && cd 5minutes && open -t hosts

  1. Change var server_user_password in vars.yml file with crypted password. This will be password for server_user_name. To generate, run:

sudo pip install passlib
python -c "from passlib.hash import sha512_crypt; import getpass; print sha512_crypt.encrypt(getpass.getpass())"

Usage

Using it is very easy. From within in 5minutes directory, run this Ansible command.

ansible-playbook 5minutes.yml -u <user_name> -K

Enter password for your server and that't it. Single command!

Try with Vagrant

You can try on Vagrant box before running this on real servers. There is Vagrantfile included.

vagrant up

Change hosts to 127.1.1.0:2200 (see vagrant up output for exact port) and run command:

ansible-playbook 5minutes.yml -u vagrant --private-key .vagrant/machines/default/virtualbox/private_key

Under the Hood

If you are wondering what it does, here it is:

  • Connects to server using SSH
  • Updates APT cache
  • Performs APT upgrade
  • Adds user specified in variable server_user_name which has sudo permission
  • Adds specified public key in variable user_public_keys in ssh authorized_keys.
  • Disables root SSH access. Yes, from next time you need to use new user to access server.
  • Disables password authentication. Again you will need to use new user with SSH public key auth method.
  • Installs ufw as firewall, fail2ban to ban IPs that show malicious signs, logwatch to analyze and report logs.
  • It also installs unattended-upgrades to enable automatic security updates.

Notes

There are few other variables that you need/might want to change. See vars: defined in vars.yml file.

  • server_user_name: default trinity
  • server_user_password: Please change this. See Ansible docs
  • logwatch_email: default [email protected], you won't get report email from logwatch if you don't change.
  • user_public_keys: default ~/.ssh/id_rsa.pub, if you use different key pair name, you need to change this path to public key file.

Ansible is perfect for this automation because it's dead simple to install and use without having to learn it.
It uses SSH as agent, so you don't need to setup anything else.

PS: This is tested on Ubuntu, as that's what I use. You are welcome to add support for other distributions :)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].