How to start Java Minecraft Server using Siri Shortcuts and SSH

iPhone on wooden table with white wallpaper and text that says "Hello"

I worked out how to start a java Minecraft server using Siri shortcuts on a Linux/Ubuntu server!

If you want to learn how keep on reading. If you want to see how it turns out, check out the next two images. Click the second image to see an animation of this running in the terminal.

animation of iPhone screen with someone saying "hey siri start minecraft"
animation of computer terminal showing minecraft server running inside a screen instance
Click for an animation of this running in the terminal

How to do this

I’m going to assume that you already have a Minecraft server running on an ssh-enabled server on your local network, or in the cloud. If it’s running in the cloud, this may be less useful unless your server needs to be restarted regularly.

If you don’t know how to set up a Minecraft server, this is the official wiki page explaining how to do it:

https://minecraft.gamepedia.com/Tutorials/Setting_up_a_server

In my setup, I run my Minecraft Server for Java on my Ubuntu Server Edition machine in my house. When the power goes off and on again, the Minecraft server doesn’t automatically start as a service (I prefer to start it manually).

In my last house, this happened frequently, so I created a start Minecraft server script to do this quickly.

The server part

  1. Create a new file called start-minecraft.sh in the same folder as your Minecraft server jar file
  2. Paste in the script from below
  3. Update the location of the folder in “# step 1” of the script to wherever your Minecraft folder is
  4. For “# step 2” on the script, change server.jar to whatever your server jar file is called
  5. Save the script file
  6. Then make the file executable by running chmod +x start-minecraft.sh

start-minecraft.sh:

#/bin/bash 
cd ~/minecraft #step 1
java -Xmx4096M -Xms4096M -jar server.jar nogui #step 2

It’s important that this file is in the same directory as your Minecraft jar file.

Now we need to create the script that Siri will run.

  1. In your home directory, create a file called siri-start-minecraft.sh
  2. Paste in the code from below
  3. Update # step 1 to point to the start-minecraft.sh file in your Minecraft directory.

siri-start-minecraft.sh:

#/bin/bash
screen -S Minecraft_Server -d -m sh ~/minecraft/start-minecraft.sh # step 1

You will now need to install a command-line utility called screen. screen allows us to start the Minecraft server in its own window, without it stopping after Siri finished running the command.

For me, on Ubuntu, I used sudo apt install screen. This may be different on your operating system. This link explains how to do this:

https://linuxize.com/post/how-to-use-linux-screen/

You will also need to make this file executable using chmod +x siri-start-minecraft.sh

In the Siri Shortcuts app

  1. Open the Shortcuts app that comes pre-installed on iOS 13
  2. Tap “Create Shortcut”
  3. Tap “Add Action”
  4. Search for ssh and choose “Run Script Over SSH”
  5. Tap “Show More”
  6. Enter the IP address or host of your ssh-enabled Minecraft server
  7. Port 22 is the default port for SSH
  8. Type in your username for the Linux server (Not your Minecraft username)
  9. (A) If you log in with a password choose password and type this in.
    (B) If using a ssh key (as I do), choose SSH Key. You can share this generated key with yourself by tapping on it and pressing share. You need to save this text and append it to the bottom of your ~/.ssh/authorized_keys file. You can easily do this running the following in your terminal on the server: echo "contents of the copied text" >> ~/.ssh/authorized_keys
  10. In the Script section at the bottom, we can tell the command to execute over ssh. In our case, ./siri-start-minecraft.sh
  11. Tap Next in the top right
  12. Give the shortcut a name such as Start Minecraft Server
  13. Tap on the command or say “Hey Siri Start Minecraft Server”
  14. The first time you do this you may be promoted to allow the host for the first time. Tap ok or yes when asked. This is normal.

Check if it worked

  1. ssh into your Linux server and run
  2. You should see one of the instances of screen called “Minecraft_Server”
  3. You can connect to it to enter commands using screen -r Minecraft_Server
  4. To disconnect from screen without closing the server, you have to enter the following key sequence: ctrl a d
Screenshot of how to check if it worked using the commands listed above
Check if it worked

Leave a Reply

Your email address will not be published. Required fields are marked *