Skip to content

Instantly share code, notes, and snippets.

@Morxander
Created December 23, 2015 12:40
Show Gist options
  • Save Morxander/d2541f388f79053bae19 to your computer and use it in GitHub Desktop.
Save Morxander/d2541f388f79053bae19 to your computer and use it in GitHub Desktop.
Setup A New Server

First of all

vim /etc/bash.bashrc

uncomment the following lines

#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
# . /etc/bash_completion
#fi 

Update & upgrade

 apt-get update && apt-get upgrade -y

Create new user login without password for ssh login with a key

adduser --disabled-password -gecos "" USER
su - USER
cd /home/USER
mkdir .ssh
chmod 700 .ssh
echo "put the key here" >> .ssh/authorized_keys
chmod 600 .ssh/authorized_keys

Make the user root

visudo

under "root ALL=(ALL) ALL", put:

USER ALL=(ALL) NOPASSWD:ALL

Setup the firewall rules

iptables -F
iptables -A INPUT -p tcp --dport 6666 -j ACCEPT
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
service iptables save

Change SSH Port

vim /etc/ssh/sshd_config 

Change The following

Port 6666
PermitRootLogin no

Restart SSH

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