Skip to content

Instantly share code, notes, and snippets.

@philipplackner
Created May 6, 2022 12:50
Show Gist options
  • Save philipplackner/bbb3581502b77edfd2b71b7e3f7b18bd to your computer and use it in GitHub Desktop.
Save philipplackner/bbb3581502b77edfd2b71b7e3f7b18bd to your computer and use it in GitHub Desktop.
1. Download Git Bash (only if on Windows)
2. Go to your users folder and open the .ssh folder. Then open Git Bash / Terminal there and generate a key pair:
ssh-keygen -m PEM -t rsa
3. Copy the key to your server:
ssh-copy-id -i <keyname> <user>@<host>
5. Login to your Ubuntu server via SSH:
ssh -i <keyname> <user>@<host>
6. Update dependencies:
sudo apt update
7. Install Java:
sudo apt-get install default-jdk
8. Open /etc/ssh/sshd_config:
sudo nano /etc/ssh/sshd_config
9. Put this string in there, save with Ctrl+S and exit with Ctrl+X:
KexAlgorithms [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
10. Restart the sshd service:
sudo systemctl restart sshd
11. Create a systemd service for your Ktor server:
sudo nano /etc/systemd/system/jwtauth.service
12. Paste this configuration in this service, then save with Ctrl+S and exit with Ctrl+X:
[Unit]
Description=Auth Service
After=network.target
StartLimitIntervalSec=10
StartLimitBurst=5
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
EnvironmentFile=/etc/environment
ExecStart=/usr/lib/jvm/default-java/bin/java -jar /root/jwtauth/jwtauth.jar
[Install]
WantedBy=multi-user.target
13. Launch the service:
sudo systemctl start jwtauth
14. Create a symlink to automatically launch the service on boot up:
sudo systemctl enable jwtauth
15. Make sure, your ports are open and you forward the traffic from the standard HTTP port to 8080:
iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
16. Then, save your iptables rules:
sudo apt-get install iptables-persistent
17. Add JWT_SECRET=<your-secret> and MONGO_PW=<your-mongo-db-pw> to your environment variables
sudo nano /etc/environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment