Initial Server Setup
Logging In
- We chose “use ssh keys to log in” when creating the server, so we need to first get our root password by “reset root password”. Next time when you log in, you will be prompted to change password.
- log into server
ssh root@your_server_ip
. Passphrase set when creating ssh keys are needed.
Adding User
Check currently available users with
cat /etc/passwd
Add a new user with
adduser <username>
If a wrong user is added accidentally, delete it with
deluser <username>
Grant this newly added user sudo privilege by “appending” it to sudo “Group”
usermod -aG sudo <username>
Logging in as New User
We can log in with the following two ways:
-
- go to
/etc/ssh/sshd_config
and changePasswordAuthentication no
toPasswordAuthentication yes
. - Restart the service after editing
sudo service ssh restart
.
- go to
Continue use SSH Authentication:
We want to copy the keys with the correct ownership and permissions, so use
rsync --archive --chown=sammy:sammy ~/.ssh /home/sammy
(Replace “sammy” with your username)- explains what –archive does
--chown=USER:GROUP
forces all files to be owned by USER with group GROUP- be sure that the source directory (
~/.ssh
) does not include a trailing slash (check to make sure you are not using~/.ssh/
) If you accidentally add a trailing slash to the command,rsync
will copy the contents of the root account’s~/.ssh
directory to thesudo
user’s home directory instead of copying the entire~/.ssh
directory structure.
We can now log in as the newly added user <username>@your_server_ip
Setting up Firewall
Before everything, you should check IPV6 is enabled by going to nano /etc/default/ufw
and check IPV6=yes
.
Set up a default profile to deny all incoming and allow all outgoing.
1
2ufw default deny incoming
ufw default allow outgoingThis is enough for a PC but not enough for a server. We would need to allow ssh, HTTP, and HTTPS.
1
2
3ufw allow ssh
ufw allow http
ufw allow httpsThe Firewall will then allow traffic from the default ports specified by these applications. For example,
ssh
uses port 22, soufw allow ssh
is equivalent toufw allow 22
.Enable and check firewall’s status:
1
2ufw enable
ufw status verbose
For more commands related to UFW, check UFW Essentials.
Install PHP
- 安装php,可用想要安装的版本替换 “7.4”:
apt install php7.4-cli
- 安装所需要的插件,可以通过
aptitude search php7.4 |grep -i mysql
来寻找对应的插件(可用自己需要的 mbstring, GD, 等替换 mysql)
conf.d - individual site configuration stored here