The motivation is: reverse ssh to remote computer, the only thing needed is that the remote is connected to the Internet.
- On 18.04 or older remote, get tmate, put it in /usr/local/bin (20.04 is 2.4.0 but has issues /w -F [tmate-io/tmate#204]):
curl -L https://github.com/tmate-io/tmate/releases/download/2.4.0/tmate-2.4.0-static-linux-amd64.tar.xz|tar xJv
sudo mv tmate-2.4.0-static-linux-amd/tmate /usr/local/bin
-
Put public keys in ~/.ssh/authorized_keys
-
Get API key from https://tmate.io/ (or host your own server)
-
Create ~/.tmate.conf
set tmate-api-key "<YOUR_API_KEY>"
set tmate-session-name "<SESSION_NAME>"
set tmate-authorized-keys "~/.ssh/authorized_keys"
Session name is chosen by you
- Create /etc/systemd/system/[email protected]
[Install]
WantedBy=multi-user.target
[Unit]
Description=Tmate-SSH
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
Restart=always
User=%i
ExecStart=/usr/local/bin/tmate -F
- Install tmate as service with
systemctl daemon-reload
systemctl start tmate@<user>
systemctl enable tmate@<user>
- You can reboot and ssh from any computer with private key:
ssh <REGISTRED_USERNAME_FROM_TMATE>/<SESSION_NAME>@nyc1.tmate.io
for HJ
tmate -S /tmp/tmate.sock new-session -d # Launch tmate in a headless mode
tmate -S /tmp/tmate.sock wait tmate-ready # Blocks until the SSH connection is established
tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}' # Prints the SSH connection string
tmate -S /tmp/tmate.sock display -p '#{tmate_ssh_ro}' # Prints the read-only SSH connection string
tmate -S /tmp/tmate.sock display -p '#{tmate_web}' # Prints the web connection string
tmate -S /tmp/tmate.sock display -p '#{tmate_web_ro}' # Prints the read-only web connection string