Top Related Projects
Quick Overview
webtty
is a lightweight, cross-platform terminal sharing tool that allows users to share their terminal sessions with others over the web. It provides a simple and secure way to collaborate on projects, troubleshoot issues, or provide remote assistance.
Pros
- Cross-Platform Compatibility:
webtty
supports multiple operating systems, including Windows, macOS, and Linux, making it accessible to a wide range of users. - Ease of Use: The tool is designed to be straightforward to set up and use, with minimal configuration required.
- Secure Connections:
webtty
uses WebSocket and TLS/SSL encryption to ensure secure communication between participants. - Lightweight and Efficient: The project is lightweight and efficient, with a small footprint and fast performance.
Cons
- Limited Customization: The tool may not offer extensive customization options, which could be a drawback for users with specific requirements.
- Dependency on WebSocket: The reliance on WebSocket technology may limit the compatibility with older browsers or environments that do not fully support this protocol.
- Potential Scalability Issues: While
webtty
is designed to be lightweight, it may face scalability challenges when handling a large number of concurrent sessions. - Lack of Advanced Features: Compared to more feature-rich terminal sharing solutions,
webtty
may lack advanced capabilities, such as file transfer, screen sharing, or collaborative editing.
Code Examples
// Establishing a WebSocket connection
conn, err := websocket.Dial("ws://example.com/webtty", "", "http://example.com")
if err != nil {
// Handle connection error
}
defer conn.Close()
This code snippet demonstrates how to establish a WebSocket connection to the webtty
server.
// Sending data through the WebSocket connection
_, err = conn.Write([]byte("Hello, webtty!"))
if err != nil {
// Handle write error
}
This code example shows how to send data through the established WebSocket connection.
// Receiving data from the WebSocket connection
buf := make([]byte, 1024)
n, err := conn.Read(buf)
if err != nil {
// Handle read error
}
fmt.Println(string(buf[:n]))
This code snippet demonstrates how to receive data from the WebSocket connection.
Getting Started
To get started with webtty
, follow these steps:
-
Install the
webtty
binary:go install github.com/maxmcd/webtty@latest
-
Start the
webtty
server:webtty serve
This will start the
webtty
server and listen for incoming connections. -
Connect to the
webtty
server:webtty connect ws://localhost:8080
This will connect to the
webtty
server and share your terminal session with others. -
Share the connection URL with other participants, and they can join the session by running the same
webtty connect
command.
That's it! With these simple steps, you can start using webtty
to share your terminal sessions and collaborate with others.
Competitor Comparisons
PTY interface for Go
Pros of creack/pty
- Provides a low-level interface for interacting with pseudo-terminals, which can be useful for building more complex terminal-based applications.
- Supports a wide range of operating systems, including Linux, macOS, and Windows.
- Actively maintained with regular updates and bug fixes.
Cons of creack/pty
- May have a steeper learning curve compared to higher-level libraries like webtty, as it requires more manual handling of terminal-related tasks.
- Lacks some of the convenience features and abstractions provided by webtty, such as built-in support for web-based terminal emulation.
Code Comparison
webtty (maxmcd/webtty):
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
conn, err := s.upgrader.Upgrade(w, r, nil)
if err != nil {
log.Println(err)
return
}
defer conn.Close()
term, err := pty.Start(exec.Command("bash"))
if err != nil {
log.Println(err)
return
}
defer term.Close()
go io.Copy(term, conn)
io.Copy(conn, term)
}
pty (creack/pty):
func Open() (*os.File, *os.File, error) {
pty, tty, err := open()
if err != nil {
return nil, nil, err
}
return os.NewFile(uintptr(pty), "pty"), os.NewFile(uintptr(tty), "tty"), nil
}
func open() (int, int, error) {
p, err := C.posix_openpt(C.O_RDWR | C.O_NOCTTY)
if err != nil {
return -1, -1, err
}
if _, err := C.grantpt(p); err != nil {
C.close(p)
return -1, -1, err
}
if _, err := C.unlockpt(p); err != nil {
C.close(p)
return -1, -1, err
}
tty := C.ptsname(p)
if tty == nil {
C.close(p)
return -1, -1, errors.New("no tty device")
}
return int(p), int(C.open(tty, C.O_RDWR|C.O_NOCTTY, 0)), nil
}
Easy SSH servers in Golang
Pros of gliderlabs/ssh
- Supports a wide range of authentication methods, including password, public key, and keyboard-interactive.
- Provides a flexible and extensible architecture, allowing for easy customization and integration with other systems.
- Includes built-in support for SSH tunneling and port forwarding.
Cons of gliderlabs/ssh
- May have a steeper learning curve compared to maxmcd/webtty, as it offers more advanced features and configuration options.
- Requires more setup and configuration to get started, especially for more complex use cases.
- May have a larger codebase and dependencies, which could impact performance or resource usage in some scenarios.
Code Comparison
Here's a brief code comparison between the two projects:
maxmcd/webtty (Go):
func main() {
app := cli.NewApp()
app.Name = "webtty"
app.Usage = "Expose your terminal over the web"
app.Action = run
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "addr",
Value: ":8080",
Usage: "Address to listen on",
},
// ...
}
app.Run(os.Args)
}
gliderlabs/ssh (Go):
func main() {
s := &ssh.Server{
Addr: ":2222",
Handler: func(s ssh.Session) {
io.WriteString(s, "Hello from gliderlabs/ssh\n")
},
}
log.Printf("Starting SSH server on %s", s.Addr)
log.Fatal(s.ListenAndServe())
}
A fast TCP/UDP tunnel over HTTP
Pros of Chisel
- Chisel supports multiple protocols, including HTTP, HTTPS, and TCP, making it more versatile than webtty.
- Chisel has a built-in authentication system, allowing for secure connections between the client and server.
- Chisel can be used to create reverse SSH tunnels, which can be useful for accessing resources behind a firewall.
Cons of Chisel
- Chisel has a more complex configuration process compared to webtty, which may be a barrier for some users.
- Chisel's documentation is not as comprehensive as webtty's, which may make it more difficult to get started.
- Chisel is written in Go, while webtty is written in Rust, which may be a preference for some developers.
Code Comparison
webtty:
fn main() {
let matches = App::new("webtty")
.version("0.1.0")
.author("Max McConnaughey <max@maxmcd.com>")
.about("A simple terminal-based web server")
.arg(
Arg::with_name("port")
.short("p")
.long("port")
.value_name("PORT")
.help("Sets the port to use")
.takes_value(true),
)
.get_matches();
}
Chisel:
func main() {
app := kingpin.New("chisel", "A fast TCP tunnel, transported over HTTP")
server := app.Command("server", "Starts a server")
serverAuth := server.Flag("auth", "Optional basic auth username:password").String()
client := app.Command("client", "Starts a client")
clientRemote := client.Arg("remote", "Remote host:port").Required().String()
clientLocal := client.Arg("local", "Local host:port").Required().String()
kingpin.MustParse(app.Parse(os.Args[1:]))
}
Share your terminal as a web application
Pros of gotty
- gotty supports multiple clients connecting to the same terminal session, allowing for collaborative work.
- gotty provides a web-based interface, making it accessible from any device with a web browser.
- gotty has a built-in authentication system, allowing for secure access to the terminal.
Cons of gotty
- gotty has a more limited feature set compared to webtty, with fewer customization options.
- gotty may have a steeper learning curve for users unfamiliar with the command-line interface.
- gotty's web-based interface may not be as responsive or user-friendly as a dedicated desktop application.
Code Comparison
webtty:
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
conn, err := s.upgrader.Upgrade(w, r, nil)
if err != nil {
log.Printf("failed to upgrade connection: %v", err)
return
}
defer conn.Close()
term, err := pty.Start(exec.Command(s.command[0], s.command[1:]...))
if err != nil {
log.Printf("failed to start terminal: %v", err)
return
}
defer term.Close()
// ...
}
gotty:
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
conn, err := s.upgrader.Upgrade(w, r, nil)
if err != nil {
s.logger.Printf("failed to upgrade connection: %v", err)
return
}
defer conn.Close()
term, err := pty.Start(exec.Command(s.command[0], s.command[1:]...))
if err != nil {
s.logger.Printf("failed to start terminal: %v", err)
return
}
defer term.Close()
// ...
}
The code snippets show the similarities in the way both webtty and gotty handle the WebSocket connection and the terminal session. The main difference is that gotty uses a logger instead of directly printing to the log.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
WebTTY
WebTTY allows you to share a terminal session from your machine using WebRTC. You can pair with a friend without setting up a proxy server, debug servers behind NATs, and more. WebTTY also works in-browser. You can connect to a WebTTY session from this static page: https://maxmcd.github.io/webtty/
Status
There are a handful of bugs to fix, but everything works pretty well at the moment. Please open an issue if you find a bug.
Installation
Download a binary from the releases page: https://github.com/maxmcd/webtty/releases
Or, install directly with Go. WebTTY requires Go version 1.9 or higher.
For Go versions below 1.7:
go get -u github.com/maxmcd/webtty
For Go versions 1.7 and up:
go install github.com/maxmcd/webtty@latest
There were recent breaking api changes in the pion/webrtc library. Make sure to run go get -u github.com/pion/webrtc
if you're running into any installation errors.
Running
> webtty -h
Usage of webtty:
-cmd
The command to run. Default is "bash -l"
Because this flag consumes the remainder of the command line,
all other args (if present) must appear before this flag.
eg: webtty -o -v -ni -cmd docker run -it --rm alpine:latest sh
-ni
Set host to non-interactive
-non-interactive
Set host to non-interactive
-o One-way connection with no response needed.
-s string
The stun server to use (default "stun:stun.l.google.com:19302")
-v Verbose logging
On the host computer
> webtty
Setting up a WebTTY connection.
Connection ready. Here is your connection data:
25FrtDEjh7yuGdWMk7R9PhzPmphst7FdsotL11iXa4r9xyTM4koAauQYivKViWYBskf8habEc5vHf3DZge5VivuAT79uSCvzc6aL2M11kcUn9rzb4DX4...
Paste it in the terminal after the webtty command
Or in a browser: https://maxmcd.github.io/webtty/
When you have the answer, paste it below and hit enter.
On the client computer
> webtty 25FrtDEjh7yuGdWMk7R9PhzPmphst7FdsotL11iXa4r9xyTM4koAauQYivKViWYBskf8habEc5vHf3DZge5VivuAT79uSCvzc6aL2M11kcUn9rzb4DX4...
Terminal Size
By default WebTTY forces the size of the client terminal. This means the host size can frequently render incorrectly. One way you can fix this is by using tmux:
tmux new-session -s shared
# in another terminal
webtty -ni -cmd tmux attach-session -t shared
Tmux will now resize the session to the smallest terminal viewport.
One-way Connections
One-way connections can be enabled with the -o
flag. A typical webrtc connection requires an SDP exchange between both parties. By default, WebTTY will create an SDP offer and wait for you to enter the SDP answer. With the -o
flag the initial offer is sent along with a public url that the receiver is expected to post their response to. This uses my service 10kb.site. The host then polls the url continually until it gets an answer.
I think this somewhat violates the spirit of this tool because it relies on a third party service. However, one-way connections allow you to do very cool things. Eg: I can have a build server output a WebTTY connection string on error and allow anyone to attach to the session.
SDP descriptions are encrypted when uploaded and encryption keys are shared with the connection data to decrypt. So presumably the service being compromised is not problematic.
Very open to any ideas on how to enable trusted one-way connections. Please open an issue or reach out if you have thoughts. For now, the -o
flag will print a warning and link to this explanation.
Top Related Projects
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot