Guide to Staking on Ethereum 2.0 (Ubuntu/Teku)

Acknowledgements

Disclaimer

Support

Prerequisites

Testnet to Mainnet

Requirements

Activation

Overview

Step 1 — Generate Staking Data

Download the Deposit Tool (Deposit CLI)

Run the Deposit Tool (Eth2 Deposit CLI)

./deposit new-mnemonic --num_validators <NumberOfValidators> --chain mainnet
deposit.exe new-mnemonic --num_validators <NumberOfValidators> --chain mainnet

Final Steps

Step 2 — Connect to the Server

# adduser <yourusername>
# usermod -aG sudo <yourusername>
# rsync --archive --chown=<yourusername>:<yourusername> ~/.ssh /home/<yourusername>

Step 3 — Update the Server

$ sudo apt update && sudo apt upgrade
$ sudo apt dist-upgrade && sudo apt autoremove
$ sudo reboot

Step 4 — Secure the Server

Modify the Default SSH Port

$ sudo ss -tulpn | grep ':<YourSSHPortNumber>'
$ sudo nano /etc/ssh/sshd_config
Port <YourSSHPortNumber>
$ sudo systemctl restart ssh

Configure the Firewall

$ sudo apt install ufw
$ sudo ufw default deny incoming
$ sudo ufw default allow outgoing
$ sudo ufw allow <yourSSHportnumber>/tcp
$ sudo ufw deny 22/tcp
$ sudo ufw allow 30303
$ sudo ufw allow 9000
$ sudo ufw enable
$ sudo ufw status numbered

Step 5 — Configure Timekeeping

$ timedatectl
$ sudo timedatectl set-ntp on
$ ntpq -p
$ sudo apt-get remove ntp

Step 6 — Set up an Ethereum (Eth1) Node

Install Go Ethereum

$ sudo add-apt-repository -y ppa:ethereum/ethereum
$ sudo apt update
$ sudo apt install geth
$ sudo useradd --no-create-home --shell /bin/false goeth
$ sudo mkdir -p /var/lib/goethereum
$ sudo chown -R goeth:goeth /var/lib/goethereum
$ sudo nano /etc/systemd/system/geth.service
[Unit]
Description=Go Ethereum Client
After=network.target
Wants=network.target
[Service]
User=goeth
Group=goeth
Type=simple
Restart=always
RestartSec=5
ExecStart=geth --http --datadir /var/lib/goethereum --cache 2048 --maxpeers 30
[Install]
WantedBy=default.target
$ sudo systemctl daemon-reload
$ sudo systemctl start geth
$ sudo systemctl status geth
$ sudo systemctl enable geth
$ sudo journalctl -fu geth.service

Check Sync Status

geth attach http://127.0.0.1:8545
> eth.syncing

Check Connected Peers

geth attach http://127.0.0.1:8545
> net.peerCount

Add Bootnodes (Optional)

$ sudo systemctl stop geth
$ sudo nano /etc/systemd/system/geth.service
ExecStart=geth --http --datadir /var/lib/goethereum --cache 2048 --maxpeers 30 --bootnodes "enode://d0b4a09d072b3f021e233fe55d43dc404a77eeaed32da9860cc72a5523c90d31ef9fab7f3da87967bc52c1118ca3241c0eced50290a87e0a91a271b5fac8d0a6@157.230.142.236:30303,enode://5070366042daaf15752fea340e7ffce3fd8fc576ac846034bd551c3eebac76db122a73fe8418804c5070a5e6d690fae133d9953f85d7aa00375d9a4a06741dbc@116.202.231.71:30303"
$ sudo systemctl daemon-reload
$ sudo systemctl start geth
$ sudo journalctl -fu geth.service

Step 7 — Download Teku

$ cd ~
$ sudo apt install curl
$ curl -LO https://artifacts.consensys.net/public/teku/raw/names/teku.tar.gz/versions/22.5.1/teku-22.5.1.tar.gz
$ tar xvf teku-22.5.1.tar.gz
$ sudo cp -a teku-22.5.1 /usr/local/bin/teku
$ sudo apt install default-jre
$ cd ~
$ sudo rm teku-22.5.1.tar.gz
$ sudo rm -r teku-22.5.1

Step 8 — Import the Validator Keys

Copy the Validator Keystore Files

Import Keystore Files into the Validator

$ sudo mkdir -p /var/lib/teku
$ sudo cp -a /$HOME/eth2deposit-cli/validator_keys /var/lib/teku
$ cd /var/lib/teku/validator_keys
$ ls
$ sudo rm <depositdatafilename>

Create the Validator Password File(s)

$ ls /var/lib/teku/validator_keys
$ sudo nano /var/lib/teku/validator_keys/<jsonfilename>.txt

Step 9 — Configure the Teku Service

Set up the Account and Directory

$ sudo useradd --no-create-home --shell /bin/false teku

Set Permissions

$ sudo chown -R teku:teku /var/lib/teku
$ ls -dl /var/lib/teku
$ sudo chmod -R 700 /var/lib/teku/validator_keys
$ sudo ls -lh /var/lib/teku/validator_keys

Create and Configure the Service

$ sudo nano /etc/systemd/system/teku.service
[Unit]
Description=Teku Eth2 Client
Wants=network-online.target
After=network-online.target
[Service]
User=teku
Group=teku
Type=simple
Restart=always
RestartSec=5
Environment="JAVA_OPTS=-Xmx4g"
ExecStart=/usr/local/bin/teku/bin/teku --data-base-path=/var/lib/teku --eth1-endpoint=http://localhost:8545 --validator-keys=/var/lib/teku/validator_keys:/var/lib/teku/validator_keys --rest-api-enabled=true --rest-api-docs-enabled=true --metrics-enabled --validators-graffiti="<yourgraffiti>"
[Install]
WantedBy=multi-user.target
--eth1-endpoint=http://localhost:8545,https://3rdPartyProviderURL
$ sudo systemctl daemon-reload
$ sudo systemctl start teku
$ sudo systemctl status teku
$ sudo systemctl enable teku
$ sudo journalctl -fu teku.service
Nov 26 21:00:50 ETH-STAKER-001 teku[41629]: 21:00:50.573 INFO  - Eth1 tracker successfully caught up to chain head
Nov 26 21:10:49 ETH-STAKER-001 teku[41629]: 21:10:49.010 INFO - 4 days 14 hours 49 minutes 34 seconds until genesis time is reached. Peers: 74

Step 10 — Fund the Validator Keys

Check the Status of Your Validator Deposits

Step 11 — Monitoring

Final Remarks and Recommended Next Steps

Further Reading

Appendix A — Updating Geth

$ sudo systemctl stop teku
$ sudo systemctl stop geth
$ sudo apt update && sudo apt upgrade
$ sudo systemctl start geth
$ sudo systemctl status geth # <-- Check for errors
$ sudo journalctl -fu geth # <-- Monitor
$ sudo systemctl start teku
$ sudo systemctl status teku # <-- Check for errors
$ sudo journalctl -fu teku.service # <-- Monitor

Appendix B — Updating Teku

$ cd ~
$ sudo apt install curl
$ curl -LO https://artifacts.consensys.net/public/teku/raw/names/teku.tar.gz/versions/22.5.1/teku-22.5.1.tar.gz
$ sudo systemctl stop teku
$ tar xvf teku-22.5.1.tar.gz
$ sudo rm -r /usr/local/bin/teku # <-- Remove the old files
$ sudo cp -a teku-22.5.1 /usr/local/bin/teku
$ sudo systemctl start teku
$ sudo systemctl status teku # <-- Check for errors
$ sudo journalctl -fu teku.service # <-- Monitor
$ cd ~
$ sudo rm teku-22.5.1.tar.gz
$ sudo rm -r teku-22.5.1

Appendix C — Adding a Validator

Appendix D — Pruning Geth

ethstaker@ETH-STAKER-002:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 796M 996K 795M 1% /run
/dev/hda1 155G 74G 82G 48% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/vda15 105M 5.2M 100M 5% /boot/efi
tmpfs 796M 0 796M 0% /run/user/1000
ethstaker@ETH-STAKER-002:~$

Start the Prune Operation

$ sudo systemctl stop geth
$ sudo journalctl -fu teku.service
$ sudo nano /etc/systemd/system/geth.service
[Unit]
Description=Go Ethereum Client
After=network.target
Wants=network.target
[Service]
User=goeth
Group=goeth
Type=simple
Restart=always
RestartSec=5
ExecStart=geth --http --datadir /var/lib/goethereum --cache 2048 --maxpeers 30 snapshot prune-state
[Install]
WantedBy=default.target
$ sudo systemctl daemon-reload
$ sudo systemctl start geth
$ sudo systemctl status geth
$ sudo systemctl stop geth
$ sudo nano /etc/systemd/system/geth.service
[Unit]
Description=Go Ethereum Client
After=network.target
Wants=network.target
[Service]
User=goeth
Group=goeth
Type=simple
Restart=always
RestartSec=5
ExecStart=geth --http --datadir /var/lib/goethereum --cache 2048 --maxpeers 30
[Install]
WantedBy=default.target
$ sudo systemctl daemon-reload
$ sudo systemctl start geth
$ sudo systemctl status geth # <-- Check for errors
$ sudo journalctl -fu geth.service # <-- Monitor
$ sudo journalctl -fu teku.service

Appendix E— Clear Systemd Journal Logs

$ sudo journalctl --disk-usage
$ sudo journalctl --flush --rotate 
$ sudo journalctl --vacuum-time=3days
$ sudo journalctl --verify

Automatically Limit Log Size

$ sudo nano /etc/systemd/journald.conf
$ sudo systemctl restart systemd-journald

Appendix F — Expanding the Logical Volume

$ sudo lvdisplay # <-- Check your logical volume size
$ sudo lvm
> lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
> exit
$ sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
$ df -h # <-- Check results

Full Disclaimer

--

--

--

Passionate about Ethereum and decentralized technology.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Somer Esat

Somer Esat

Passionate about Ethereum and decentralized technology.

More from Medium

Has any DAO shown profitability yet?

Rocket Pool — Sustaining Decentralization on Ethereum

A Guide to Stablecoin