2021-11-26 15:42:51+00:00

For systems administrators maintaining remote Linux terminals or POS machines behind firewalls, setting up screen sharing is critical to debug customer issues. While SSH is powerful, visual debugging of application displays requires GUI-based remote desktop connections. Automating the installation and registration of TeamViewer on headless Linux servers allows teams to provision remote access tools programmatically without requiring manual clicks on-site.

By scripting the deb package installation, binding to system dbus runtimes, and registering hosts to organizational accounts, we can automate TeamViewer provisioning.


1. Automated Installation and Configuration Script

We write a bash script to fetch the package, verify dependencies, and configure TeamViewer to boot headless without showing system popups:

#!/bin/bash
# install_teamviewer.sh
set -euo pipefail

TV_DEB="teamviewer_amd64.deb"
TV_URL="https://download.teamviewer.com/download/linux/$TV_DEB"

echo "Downloading TeamViewer..."
wget -q "$TV_URL" -O "$TV_DEB"

echo "Installing package dependencies..."
sudo apt-get update
sudo apt-get install -y ./$TV_DEB || sudo apt-get install -f -y

# Configure headless daemon options
echo "Configuring TeamViewer settings..."
sudo teamviewer license accept
sudo teamviewer daemon stop

# Modify daemon configurations programmatically
sudo teamviewer passwd "TemporaryAdminPassword123"

# Start the TeamViewer service
sudo teamviewer daemon start
echo "Installation complete!"

2. Binding Remote Access to Organizational Accounts

To access the client terminal without inputting single-use session IDs, we bind the device to a company administrator account using the TeamViewer API command tool:

# Assign device ownership to administrator account
# TV_TOKEN is the registration token from the TeamViewer Management Console
TV_TOKEN="1234567-abcdefghijklmnopqrst"

echo "Registering device assignment..."
sudo teamviewer assignment --id "$TV_TOKEN" --alias "$(hostname)-prod" --group "Production-Edge"

# Print ID to verification logs
teamviewer info | grep "TeamViewer ID"

3. Ensuring Persistent Startup

We configure the TeamViewer daemon to restart automatically following system power losses by setting systemd configuration overrides: systemctl enable teamviewerd.service. This ensures remote gateways regain support accessibility as soon as network interfaces boot.