Configuring a New Cloud Server
A baseline Ubuntu server-hardening checklist covering SSH changes, root-login restrictions, sudo access, and essential security settings.
The goal is simple: keep the server from being compromised and turned into someone else’s bot.
Notes
Host: Vultr Japan. System: Ubuntu 12.04 64-bit.
After logging in as root for the first time, install Vim to make the remaining changes easier:
apt-get install vimChange the default SSH port and disable root login
Edit /etc/ssh/sshd_config, choose a non-default port, and disable direct root access:
Port 23333PermitRootLogin noRestart SSH after saving the file:
service ssh restart# or/etc/init.d/ssh restartAdd a separate login user
useradd testuserpasswd testuserChange the user’s default shell from /bin/sh to /bin/bash in /etc/passwd; otherwise command completion will not work as expected.
vim /etc/passwdGrant administrator privileges
Use visudo so concurrent edits cannot corrupt the sudoers file. Its default editor is vi; set EDITOR=vim for this invocation if preferred:
EDITOR=vim visudoAdd the user and allow passwordless sudo if that is appropriate for the server:
testuser ALL=(ALL) NOPASSWD:ALL# ortestuser ALL=(root) NOPASSWD:ALLFinally, add familiar aliases and terminal colors to the new user’s shell configuration. Key-based SSH login can also be configured, although I did not consider it necessary for this server. These steps reduce routine SSH risk, but they do not protect a server against DDoS attacks.