Login

Navigation

This articles is published 602 days ago and last updated 560 days ago, some information may be out of date.

Alpine Linux share the terminal over the web (ttyd).png

What is ttyd?
ttyd is a simple command-line program that allows you to share a terminal session over the web. It provides a web-based terminal interface for interacting with a Linux system, making it possible to access the system remotely from a web browser.

Install ttyd in Alpine Linux

Open the terminal and type the following command to update the packages list:

apk update

Install the ttyd package by typing the following command:

apk add ttyd

Once the installation is complete, you can use the ttyd command to start the ttyd server.

For example, to start the ttyd server on port 7681, use the following command:

ttyd -p 7681 /bin/sh

This command will start the ttyd server and run the /bin/sh shell in it.

You can now access the ttyd server by opening a web browser and navigating to http://<ip_address>:7681.

Replace <ip_address> with the IP address of the server where the ttyd server is running.

That's it! You have now installed and started the ttyd server on Alpine Linux.


Make ttyd start-up on boot

Create a new file in the /etc/init.d/ directory using your preferred text editor. For example, you can use the following command to create a file named ttyd:

vi /etc/init.d/ttyd

Add the following content to the ttyd file:

#!/sbin/openrc-run

description="ttyd service"
command="/usr/bin/ttyd -p 7681 login &"
command_args=""
pidfile="/run/ttyd.pid"

depend() {
    after network
}

start_pre() {
    mkdir -p /run/ttyd
}
OptionDescription
/usr/bin/ttydSpecifies the path to the ttyd binary.
-p 7681Specifies the port number that ttyd should listen on for incoming connections. In this case, it is set to 7681 (default).
loginSpecifies the command to run after a user connects to ttyd. In this case, it is set to login, which starts a new login session.
&Runs the command in the background, allowing the terminal to be used for other commands while ttyd continues to run.

Creates a new service definition for ttyd, defining the command to run and the PID file location.

Adjust the command line to use your desired options for ttyd.

Save and exit the file.

Make the ttyd script executable using the following command:

chmod +x /etc/init.d/ttyd

Add the ttyd service to the startup list using the following command:

rc-update add ttyd
  • service ttyd added to runlevel default

This command adds the ttyd service to the default runlevel, so it will start up automatically on boot.

That's it! You have now configured ttyd to start up on boot in Alpine Linux.


Conclusion

ttyd, which allows users to interact with the shell session in real-time using a web-based terminal interface.
ttyd also is a useful tool for remote administration and troubleshooting of Linux systems.


Related