Table of Contents#
- What is GoTTY?
- Key Features and Use Cases
- Installation Guide
- Getting Started: Your First GoTTY Session
- Basic Usage and Common Options
- Advanced Configuration and Security
- Important Security Considerations
- Conclusion
- References
What is GoTTY?#
At its core, GoTTY is a simple command-line tool that takes any CLI application and serves it as a web application. While it can host any application, its most common and powerful use case is sharing the terminal itself (/bin/bash, zsh, etc.).
It works by creating an HTTP server that serves a HTML/JavaScript-based terminal emulator (using xterm.js). When you connect to the server via a web browser, a WebSocket connection is established. This WebSocket acts as a bridge, relaying the input from your browser to the underlying TTY (terminal) and sending the output from the TTY back to the browser. This creates a real-time, bidirectional terminal session over the web.
Key Features and Use Cases#
- Live Demos & Presentations: Perfect for presenting command-line workflows during meetings or conferences without fiddling with screen sharing.
- Remote Assistance: Help a colleague troubleshoot a server issue by allowing them to see your terminal or even by giving them controlled access.
- Education & Training: Teachers can demonstrate complex command-line operations to students in real-time.
- Limited Access Sharing: Provide temporary, browser-based access to a terminal for users who shouldn't have full SSH credentials.
- Container & CI/CD Debugging: Temporarily expose a terminal session from within a container or a CI/CD pipeline for debugging purposes.
Installation Guide#
Getting GoTTY up and running is straightforward. Here are the most common methods.
Method 1: Using a Package Manager (easiest)#
If you are on a system with brew (macOS or Linuxbrew), this is the simplest method.
# On macOS or Linux with Homebrew installed
brew install gottyFor Arch Linux users, it's available in the AUR.
Method 2: Downloading the Binary#
Visit the GoTTY GitHub Releases page. Download the appropriate archive for your architecture (e.g., gotty_2.0.0-alpha.3_linux_amd64.tar.gz), extract it, and move the binary to your PATH.
# Example for Linux AMD64
wget https://github.com/sorenisanerd/gotty/releases/download/v2.0.0-alpha.3/gotty_2.0.0-alpha.3_linux_amd64.tar.gz
tar -xzf gotty_2.0.0-alpha.3_linux_amd64.tar.gz
sudo mv gotty /usr/local/bin/Method 3: Building from Source#
Ensure you have Go (1.19+) installed.
go install github.com/sorenisanerd/gotty@latestThe binary will be placed in your $GOPATH/bin directory (typically ~/go/bin/).
Getting Started: Your First GoTTY Session#
Let's start with the most basic command. This will share your current terminal session.
-
Open your terminal.
-
Run the following command:
gotty bashThis starts a GoTTY server hosting a
bashshell. -
By default, GoTTY listens on port
8080. Open your web browser and navigate tohttp://your-server-ip:8080.
You should now see a terminal interface in your browser that is a mirror of the bash session you started on the server. Anything you type in the browser will be executed on the server.
Warning: This basic setup is highly insecure as it is accessible to anyone on the network without a password. The following sections will show you how to secure it.
Basic Usage and Common Options#
GoTTY is highly configurable. Here are the most essential options.
Authentication#
The single most important option. Always use it to password-protect your session.
gotty -c 'username:password' bashNow, when you access the page, you will be prompted for the credentials.
Port Binding#
Change the default port (8080) to something else using the -p flag.
gotty -p 9090 -c 'admin:secret123' bash
# Now access via http://your-server-ip:9090Whitelisting IPs#
To restrict access to a specific IP address (e.g., your own), use the -i (interface) flag.
gotty -i 192.168.1.100 -c 'user:pass' bash
# The server will only listen on the interface with IP 192.168.1.100Running a Specific Command#
Instead of sharing an interactive shell, you can share a single, long-running command. For example, to share the output of top:
gotty -c 'user:pass' -- topThis is great for monitoring purposes. The command will run, and users can see its live output but cannot send input.
Advanced Configuration and Security#
For production or internet-facing use, basic authentication is not enough. You should use encryption and additional layers of security.
Using TLS/SSL (--tls)#
If you have an SSL certificate, you can serve GoTTY over HTTPS.
gotty -p 443 --tls --tls-cert fullchain.pem --tls-key privkey.pem -c 'user:pass' bashUsing a Reverse Proxy (nginx)#
A more robust setup is to place GoTTY behind a reverse proxy like nginx. This allows you to:
- Use a domain name.
- Handle SSL termination with Let's Encrypt (e.g., using Certbot).
- Add additional security headers.
- Use a path-based route (e.g.,
example.com/gotty).
Example nginx configuration:
# Inside your server block
location /gotty/ {
proxy_pass http://127.0.0.1:8080/; # Proxy to GoTTY running locally
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 86400; # WebSocket timeout
}You would then run GoTTY locally on port 8080: gotty -p 8080 -c 'user:pass' bash and access it securely at https://yourdomain.com/gotty.
Read-Only Mode#
For scenarios where you only want to share your screen without allowing others to type (e.g., for a demo), use the read-only flag.
gotty -r -c 'user:pass' bashImportant Security Considerations#
GoTTY is a powerful tool, and with great power comes great responsibility. Misconfiguration can lead to severe security risks.
- NEVER RUN GoTTY WITHOUT AUTHENTICATION ON A PUBLIC NETWORK. This is equivalent to leaving an unlocked terminal open for anyone to use.
- Prefer HTTPS over HTTP. Transmitting passwords over HTTP is insecure. Always use
--tlsor a reverse proxy with SSL. - Use Strong Credentials. Don't use simple or default usernames and passwords.
- Limit Access with Firewalls. Use your server's firewall (e.g.,
ufw) to restrict access to the GoTTY port only from trusted IP ranges. - Consider it a Temporary Tool. GoTTY is ideal for short-term sharing. Do not leave it running indefinitely.
- Understand the Risks of Interactive Sessions. Anyone with access can run any command that the user running the
gottyprocess has permission to run. It's often safer to run GoTTY as a non-root user.
Conclusion#
GoTTY is an incredibly useful utility that bridges the gap between the traditional command line and modern web-based collaboration. It simplifies tasks like remote debugging, teaching, and demystifying command-line operations. While its setup is simple, a secure deployment requires careful attention to authentication, encryption, and access controls.
By following the practices outlined in this guide, you can safely unlock the power of sharing your terminal as a web application, making your workflow more collaborative and efficient.
References#
- Official GoTTY GitHub Repository: https://github.com/sorenisanerd/gotty - The definitive source for documentation, issue tracking, and the latest releases.
- xterm.js: https://xtermjs.org/ - The powerful terminal frontend component used by GoTTY.
- nginx Documentation: https://nginx.org/en/docs/ - For detailed information on configuring a reverse proxy.
- Let's Encrypt: https://letsencrypt.org/ - For obtaining free SSL/TLS certificates.