Introduction
Have you ever wanted to share your terminal on the browser? well, now you can with ttyd! ttyd is a simple command-line tool that allows you to share your terminal on the browser. It is a great tool for remote terminal sharing and collaboration. In this post, I will show you how to install and use ttyd on the docker to share your terminal on the browser. ☺️
Requirements
- A computer or a cloud server
- Docker installed on your computer or cloud server
In this post, I will show you how to install and use ttyd on the docker to share your terminal on the browser.
Installation
- To install ttyd on your computer or cloud server, you need to have docker installed. If you don't have docker installed, you can follow the instructions on the official docker website for your operating system.
- Once you have docker installed, you can save the following script to a file called docker-compose.yml.
1version: "3.8"
2services:
3 web:
4 image: tsl0922/ttyd:latest
5 container_name: ttyd
6 ports:
7 - ${PORT}:${PORT}
8 command: >
9 ttyd
10 -c ${USER}:${PASSWORD}
11 -W
12 --terminal-type=xterm-256color
13 -t titleFixed=TTYD
14 -t cursorStyle=bar
15 -t cursorBlink=true
16 -t cursorInactiveStyle=underline
17 -t drawBoldTextInBrightColors=true
18 -t cursorWidth=4
19 -t lineHeight=1
20 -t rightClickSelectsWord=true
21 -t 'theme={"background": "black","foreground":"green"}'
22 -t fontSize=16
23 -t scrollOnUserInput=true
24 -t convertEol=true
25 -t max-clients=1
26 bash
27 tty: true
28 stdin_open: true
29 volumes:
30 - ./ttyd:/root/.ttyd
31 logging: # Logging configuration for the container
32 driver: "json-file"
33 options:
34 max-size: "10m"
35 max-file: "3"
36 env_file:
37 - .envon the same folder create the env file called .env and save the following content to it:
PORT=7681
USER=user
PASSWORD=test1235- The above script will run ttyd with the username user and password test1235 . You can change the username and password to any other username and password you like. In addition, it will create a docker container with ttyd running on port 7681. You can change the port to any other port you like.
Once you have saved the script, you can run the following command to start the ttyd container:
docker-compose upor run it in the background
docker-compose up -d
- If you run it on a cloud server, you can access the terminal on the browser by visiting http://your-server-ip:7681 in your browser. but before that you have to open the http port on your cloud server if it is a linux distribution . you can do that by running the following command:
Bonus
- You can also costumize the ttyd browser terminal by running the following command or saving it to a bash script called
install.sh:
1Update package lists
2apt-get update &&
3apt-get upgrade -y &&
4
5apt-get install -y zsh &&
6sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
7
8apt-get install -y build-essential &&
9apt-get install -y curl &&
10apt-get install -y wget &&
11apt-get install -y git &&
12apt-get install -y vim &&
13apt-get install -y nano &&
14apt-get install -y htop &&
15apt-get install -y tmux &&
16apt-get install -y screen &&
17apt-get install -y emacs &&
18apt-get install -y gedit &&
19
20
21apt-get install -y net-tools &&
22apt-get install -y openssh-server &&
23apt-get install -y ufw &&
24apt-get install -y dnsutils &&
25apt-get install -y nmap &&
26apt-get install -y tcpdump &&
27apt-get install -y whois &&
28apt-get install -y iptables &&
29
30
31apt-get install -y zip unzip &&
32apt-get install -y tar &&
33apt-get install -y rsync &&
34
35apt-get install -y sysstat &&
36apt-get install -y iotop &&
37apt-get install -y iftop &&
38apt-get install -y lsof &&
39apt-get install -y ncdu &&
40
41apt-get install -y python3 python3-pip &&
42apt-get install -y openjdk-11-jdk &&
43apt-get install -y nodejs npm &&
44apt-get install -y ruby ruby-dev &&
45apt-get install -y clang &&
46apt-get install -y gdb &&
47apt-get install -y cmake &&
48apt-get install -y maven &&
49apt-get install -y gradle &&
50apt-get install -y php &&
51apt-get install -y mysql-server &&
52apt-get install -y postgresql postgresql-contrib &&
53apt-get install -y mercurial &&
54
55apt-get install -y software-properties-common &&
56apt-get install -y gnupg &&
57apt-get install -y ca-certificates &&
58apt-get install -y tree &&
59apt-get install -y jq &&
60apt-get install -y fzf &&
61apt-get install -y ffmpeg &&
62apt-get install -y imagemagick &&
63apt-get install -y parted &&
64apt-get install -y gparted &&
65apt-get install -y bleachbit &&
66
67apt-get install -y vlc &&
68apt-get install -y gimp &&
69
70apt-get install -y thunderbird &&
71apt-get install -y pidgin &&
72
73apt-get install -y neofetch &&
74
75apt-get install -y gnome-screenshot &&
76apt-get install -y keepassxc &&
77apt-get install -y rangeron the terminal run the following command:
chmod +x ./install.sh
./install.sh
the above commands will install some useful tools like vim, nano on the ttyd container.
Conclusion
ttyd is easy to run and costumize for your needs. It is also secure and can be run on a cloud server. I hope you find this post helpful. If you have any questions or suggestions, feel free to leave a comment below. ❤️