TeamViewer "FAILED TO establish the default connection to the WindowServer"
This should work (sudo privs required!)


Login with ssh on the remote Mac
Enter:

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart  -activate -configure -access -on -privs -all -restart -agent 


to enable remote management 
open Screen Sharing locally (/System/Library/CoreServices/Applications/Screen Sharing.app)
Enter the IP of the remote Mac
Enter your remote user creds
Log in with your remote user creds at the login screen
Launch and configure TeamViewer


Depending on the security settings of the remote network (firewall etc.) you have to use the same tunnel/channel as the ssh connection.

The steps above only work for macOS up to High Sierra (10.13.6).



In macOS Mojave and later kickstart only works with managed devices and special profiles, if screen sharing wasn't enabled previously:

Use the kickstart command-line utility in macOS Mojave 10.14 and later

Eventually, you have to access the remote Mac personally and set up screen sharing in System Prefs > Sharing (to access it via VNC) or launch and configure TeamViewer.