SSH into your server at root:
ssh [email protected]
Crate a new user:
adduser my_username
Make the new user a sudo user:
usermod -aG sudo my_username
Ensure your server allows password auth (or dont, but it's helpful for now) by opening sshd config and ensuring password authentication is allowed:
sudo vim /etc/ssh/sshd_config
...
# Find line for PasswordAuthentication and set to `yes`
PasswordAuthentication yes
...
# Save
Reload sshd daemon:
sudo systemctl reload sshd
Now su into your new user and make the file needed for adding ssh key login to your new user:
su my_username
...
cd ~ && mkdir .ssh && touch .ssh/authorized_keys
Now exit and add your public key to each user:
exit
...
# Copy public key to authorized_keys for each server user
cat ~/.ssh/id_rsa.pub | ssh [email protected] 'cat >> .ssh/authorized_keys'
cat ~/.ssh/id_rsa.pub | ssh [email protected] 'cat >> .ssh/authorized_keys'
If you need to add subdomains for things like api.myserver.com
or dev.myserver.com
, use the following guide.
- Create a new droplet for your subdomain. Your subdomain will be handled by its own droplet with its own IP address. When you give it its hostname, name it whatever you want your subdomain's domain to be (so it's easily recognizable) - for this example, name it
api.myserver.com
. - Go to Digital Ocean and go to the Networking tab (at the time of this writing that's at https://cloud.digitalocean.com/networking).
- Select your domain,
myserver.com
. - Click to add a
A
record. - Under "Hostname", enter
api
. - Under "WILL REDIRECT TO", select your api droplet,
api.myserver.com
. - Optionally, set the TTL to something else - idk why but I've been using 1800.
- Create the
A
record by clicking "Create Record". - Click to add a
CNAME
record. - Under "Hostname", enter
*.api
. - Under "IS AN ALIAS OF", enter
api.myserver.com.
(note: The period at the end is not a typo, don't forget it). - Optionally, set the TTL to something else. idk why but Digital Ocean defaults
CNAME
records to a longer TTL, I'm guessing because it has something to do with the "alias" aspect. I really don't know right now so I haven't been messing with it. - Create the
CNAME
record by clicking "Create Record".
Should be good to go. If you want to test that it worked, you can ping you api and compare the IP address you get back with the one you get from pinging your server without the subdomain. Name servers may not have propogated but I havent ran into this issue yet. See here: https://www.digitalocean.com/community/tutorials/how-to-set-up-and-test-dns-subdomains-with-digitalocean-s-dns-panel.
thanks