The Installation Instructions for Ubuntu suggest running
geth from the command line, how can I run it as daemon process / service on Ubuntu?
Run as a systemd service
Create a file
[Unit] Description=Ethereum go client [Service] Type=simple ExecStart=geth 2>%h/.ethereum/geth.log [Install] WantedBy=default.target
systemctl --user enable geth.service systemctl --user start geth.service
Alternatively you could use screen:
sudo apt-get update && sudo apt-get install screen -y
Then you can make a bash similar to this (
#!/usr/bin/env bash echo "Starting geth" screen -dmS geth /usr/bin/geth --verbosity 3
now let's make it executable:
sudo chmod +x ~/geth.sh
You can now run the bash
You attach to the screen with screen -x geth
You detach from the screen by pressing CTRL + a then d
If you want to attach to the geth console after the process runs in the background (or in screen), you can use:
Or simply fork it in background:
When starting geht, put a
& at the end of the command in a terminal:
geth --rpc &
Before closing the terminal you should disown the process:
You could also pipe the logs to a file like that:
geth --verbosity 4 --rpc 2>> /path/to/logfile
But don't forget to disown it before you close the terminal.
Just using this command is enough for me:
nohup geth --rpc &
To check if service is running:
ps ax | grep geth
To explore last log messages:
tail -f nohup.out
To stop the service I use:
Here is an update to 5chdn's answer that uses
systemd. This shows how to run a headless
geth on your Ubuntu server.
Of course, you must install the command line tools first, see https://www.ethereum.org/cli. You should also run MyEtherWallet on your normal desktop computer to create an account + private key so you can receive funds.
Step 1: put on your cape
Other steps here are based on you running as root. If you are not running as root then learn about using systemd with user processes. tl;dr in this case they would only run after you login, but you can configure so a user service starts as boot
Step 2: make a service
cat > /root/geth.service <<EOF [Unit] Description=Ethereum go client [Service] Type=simple ExecStart=/usr/bin/geth --etherbase 0xe677698ab732Aa1E56CF2A7997a00e3FA6F5bD88 2>%h/.ethereum/geth.log [Install] WantedBy=default.target EOF
Above, you can substitute your own wallet's etherbase. If you don't specify an etherbase then
geth will emit a warning.
Step 3: run it
systemctl --user enable /root/geth.service systemctl --user start geth.service
This will run it now and after you reboot.
Step 4: test it
sleep 5 # The geth server takes a few seconds to boot up geth attach
geth attach is successful, you will know the
geth server is running, and you'll see:
If something messed up then you'll see:
Fatal: Unable to attach to remote geth: dial unix /root/.ethereum/geth.ipc: connect: connection refused
Though the accepted answer is great, it didn't work for me. Most likely because I am on AWS Linux AMI (eugh, I know). I intend on switching at some point (systemctl not So far, this seems to have worked for me:
- Create file /etc/init.d/geth-testnet
#!/bin/bash #chkconfig: 2345 20 80 #description Start RPC testnet su ec2-user -c '/path/to/geth --verbosity 3 --testnet --rpc --rpcaddr="0.0.0.0" --rpccorsdomain="*" --rpcapi="db,eth,net,web3,personal"'
chmod +x geth-testnet chkconfig --add geth-testnet chkconfig --level 345 geth-testnet on