- So for this one am going to be using DigitalOcean cloud provider , create a droplet with the basic storage capacity.
- Add you public ssh key to digitalOcean to authenticate yourself with the server when you connect to it for root user
- For the steps to create a server on digitalocean you read about them here and then Configure the firewall to open ssh port 22 (because by default the ssh service listens on port 22) for your ip to ensure ssh secure connection, why: We ideally don't want anyone an authorized to ssh into our server for security best practice
- After creating your droplet on digitalocean, head off to your local terminal and ensure you do have your public ssh key in your at
/home/youruser/.ssh/id_rsa.pub,if you don't have it there then you can create one withssh-keygen -t rsa
- Then ssh into the remote server as a root user for now ie
ssh root@<remote-server-ip> Once in the linux terminal install java 17 ie
sudo apt update &&
sudo apt install openjdk-17-jdk -y
using the linuxaptpackage manager and then create a linux user ie with theaddusercommand to avoid running java application as a root user for security best practices.You can also grand that user privileges to perform administrative tasks with
usermod -aG sudo cliffand also create an.ssh
folder with theauthorized_keysfile in the user's home directory of your linux user. Add in the users ssh public to authenticate them with the remote server
Now we copy the built, compiled jar file from our build tool ie maven or gradle on our local machine with scp build/libs/java-react-example.jar root@<remote-ip>:/root to the remote server on the cloud.
Then switch to user we created using su - cliff and run java -jar java-react-example.jar , this starts the Java application contained in the jar file which will be listening at a particular port when you run ps aux | grep java to inspect the process . This port needs to be opened in the firewall configuration rule to all sources

Top comments (0)