diff --git a/blog/initial-server-setup.html b/blog/initial-server-setup.html index a24336c..61455e2 100644 --- a/blog/initial-server-setup.html +++ b/blog/initial-server-setup.html @@ -53,13 +53,17 @@
You want to avoid using root as much as possible in regular use, so a new user for yourself is a must
-adduser
-usermod -aG sudo
+adduser $USERNAME$
+usermod -aG sudo $USERNAME$
- *replace
*replace $USERNAME$ with the user you want to create, e.g. nathan
If the server is a physical PC in your home you will need to set a static IP, otherwise your router could assign a differnent IP on reboot, and this would mess with port forwarding, and internal DNS.
+Set static IP for local server
+If you've set the static IP for your local server, you'll also have an additional step when making public (internet served) services, as unlike a VPS your ISP will likely have all outbound ports disabled by default
+Port forward your local server
Although this is optional, I recommend it, as SSH (secure shell) will be the primary means of access to the server.
@@ -79,10 +83,10 @@ usermod -aG sudoUFW (Uncomplicated Firewall) is a simple to use firewall, that can be used to easily open/close ports on your server.
We'll install ufw, deny access inwards to all ports, but allow our server to access any ports outwards. We will then manually allow inwards traffic to the SSH port we set, in this case 2020
-apt install ufw
-ufw deny incoming
-ufw allow outgoing
-ufw allow 2020
+ apt install ufw
+ufw deny incoming &&
+ufw allow outgoing &&
+ufw allow 2020 &&
ufw enable
If there are any other ports that need to be opened in the future this can be done with:
ufw allow
@@ -92,8 +96,9 @@ ufw enable
Setting the name for a server is an important step, but the name doesn't need to be serious
-vim /etc/hosts
-vim /etc/hostname
+ vim /etc/hosts
+ and
+vim /etc/hostname
Within both of these files the hostname should be changed to the same thing
@@ -107,26 +112,51 @@ vim /etc/hostnameThis is a two part section, and I recommend using this every time you SSH into a server from a new PC
-ssh @ -p 2020
+ ssh $USER$@$HOST$ -p 2020
This will likely display a message asking to verify the key for the server. This is to prevent man-in-the-middle attacks, so I reccommend verifying this whenever asked.
To check the key for the server, you need to run this command on the server.
-ssh-keygen -l -f /etc/ssh/ssh_host__key.pub
+ ssh-keygen -l -f /etc/ssh/ssh_host_$KEY$_key.pub
- Replace
Replace $KEY$ with the key the message is asking about (e.g. ecdsa, rsa, ed25519). Then if key the server shows matches that on your PC you are SSHing from, type yes and hit enter
Updates to a server typically want to be done by a human in case things go wrong, but smaller updates can be set to be done automatically
-These are a few things I personally like to have on a basic server
+These are a few things I personally like to have on a basic server. If you have your own preferences, dotfiles, or intend to use oh-my-zsh fell free to skip over this.
+Warning this is a preference you may not want to use if you're a beginner, and/or don't use VIM (text editor), as it sets the terminal to work more like VIM
+Open your .bashrc file in your editor of choice
+
vim ~/.bashrc
+ Add the following to the bottom of the file
+set -o vi
+
Instead of typing out long commands you can alias them, and type a shorthand version.I've written an article about aliases that explains setting up, and aliases I use. Below are some essentials for those that don't want to jump to another article.
+alias ll="ls -lhtr"
+alias df="df -h"
+alias lsm="ls -t -1"
+alias count="find . -type f | wc -l"
+
Sometimes a new system doesn't have this by default, and it's probably the thing I use most after ls.
+Add, or create an .inputrc file
+vim ~/.inputrc
+ Add the following line to the file
+"C-l": clear-screen
+
This will make your terminal look a little nicer, and display a directory path, user, and hostname. A ridiculously useful feature if you're managing multiple servers, or virtual machines
+This is also in the .bashrc file, so open that up
+vim ~/.bashrc
+ Then add the following to the bottom of the file
+export PS1="\[\e[01;33m\]\u\[\e[0m\]\[\e[00;37m\]@\[\e[0m\]\[\e[01;36m\]\h\[\e[0m\]\[\e[00;37m\] \t \[\e[0m\]\[\e[01;35m\]\w\[\e[0m\]\[\e[01;37m\] \[\e[0m\]\n$ "
+ If you want to customise your terminal, you can do so with .bashrc PS1 generator.
Keep the server up-to date as much as possible