I want to record my Amazon Elastic Compute Cloud (Amazon EC2) Linux terminal session or SSH session in text mode and then share it or replay it later. How can I do this?
You can record your SSH or terminal session to a file using the script command. If you need help, you can run the man script command to access the user manual.
Record the session
1. Open an SSH terminal. Replace the example IP address in the following command with your IP address or hostname.
$ ssh 198.51.100.0
2. Start a script session. In the following command, -a enables append mode and -t sets a timing file.
$ script -a -t timingfile.txt typescript.txt
3. Run any commands that you want to record. The commands and any output are recorded.
4. When done, exit the script session by typing exit or pressing Ctrl-D.
5. Files named typescript.txt and timingfile.txt contain the recorded data. You can share these files as needed.
Replay the session
1. Copy the typescript.txt and timingfile.txt files to a Linux (or Unix) server or replay them from the same server.
2. Use the following command to show the complete output of the typescript.txt file immediately without a delay:
$ cat typescript.txt
3. Use the following command to replay the file with normal timing:
$ scriptreplay --timing=timingfile.txt typescript.txt
4. Use the following command to replay the file with a timing divisor to enable faster replay:
$ scriptreplay --timing=timingfile.txt typescript.txt -d 10
Note: The Linux executables script and scriptreplay come pre-installed by default, so they don't need to be installed separately. If you do need to install them, use the following command that corresponds to your operating system:
Ubuntu 16 and Ubuntu 18:
sudo apt install bsdutils
sudo yum install util-linux-ng
RHEL 7, Amazon Linux 1, and Amazon Linux 2:
sudo yum install util-linux
How to record SSH sessions established through a bastion host