How can I record my Linux terminal session in text mode and share or replay it later?

Lesedauer: 2 Minute
0

I want to record my Amazon Elastic Compute Cloud (Amazon EC2) Linux terminal session or SSH session in text mode. Then, I want to share it or replay it.

Short description

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.

Resolution

Record the session

  1. Open an SSH terminal:

    ssh -i /path/KEY_PAIR_NAME.pem INSTANCE_USERNAME@IP_ADDRESS

    Be sure to replace these placeholder values:

    • KEY_PAIR_NAME: The file name of your SSH key pair
    • INSTANCE_USERNAME: The username of the account that you used to launch the instance
    • IP_ADDRESS: The instance's IP address or public DNS name

    For more information, see Connect to your Linux instance using an SSH client.

  2. Start a script session. In the following command, --timing sets a timing file:

    $ script --timing=timingfile.tm typescript.txt
  3. Run any commands that you want to record. This also records the commands' outputs.

  4. To exit the script session, type exit or press Ctrl-D.

  5. The files typescript.txt and timingfile.tm contain the recorded data. You can share these files as needed.

Replay the session

  1. Copy the typescript.txt and timingfile.tm files to a Linux or Unix server, or replay them from the same server.

  2. To show the complete output of the typescript.txt file without delay, run the following command:

    $ cat typescript.txt
  3. To replay the file with normal timing, run the following command:

    $ scriptreplay --timing=timingfile.tm typescript.txt
  4. To replay the file with a timing divisor and allow faster replay, run the following command:

    $ scriptreplay --timing=timingfile.tm typescript.txt -d 10

    Note: The Linux commands script and scriptreplay come pre-installed by default, so you don't need to install them separately. To reinstall them, run one of the following commands, depending on your operating system:

    Ubuntu 18 and Ubuntu 20

    sudo apt install bsdutils

    RHEL 7, RHEL 8, Amazon Linux 1, Amazon Linux 2, and Amazon Linux 2023

    sudo yum install util-linux

Related information

How to record SSH sessions established through a bastion host

AWS OFFICIAL
AWS OFFICIALAktualisiert vor 7 Monaten