Bookmark this page

Guided Exercise: Transferring Files Remotely

Move files between Linux systems by using command-line utilities.

Outcomes

  • Access a remote computer by using the SSH protocol.

  • Copy a file to a remote computer.

As the student user on the workstation machine, use the lab command to prepare your environment for this exercise, and to ensure that all required resources are available.

[student@workstation ~]$ lab start network-remote

Instructions

  1. On the servera machine, enable remote login over SSH. Use student as the user and student as the password to log in. Use the student user sudo privileges to run the systemctl command.

    1. Log in to the servera machine.

      [student@workstation ~]$ ssh student@servera
      student@servera's password: student
      ...output omitted...
      [student@servera ~]$
    2. Enable the SSH service. Use the systemctl command with sudo privileges to enable the service.

      [student@servera ~]$ sudo systemctl enable --now sshd
      [sudo] password for student: student
    3. Verify that the SSH service is active.

      [student@servera ~]$ sudo systemctl status sshd
      ● sshd.service - OpenSSH server daemon
           Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
           Active: active (running) since Mon 2023-11-20 14:05:18 EST; 3h 23min ago
      ...output omitted...
  2. Review the system information and IP addresses for the servera machine.

    1. Review the fully qualified domain name (FQDN) and operating system version of the servera machine.

      [student@servera ~]$ hostnamectl
       Static hostname: servera.lab.example.com
      ...output omitted...
      Operating System: Red Hat Enterprise Linux 9.1 (Plow)
      ...output omitted...
       Hardware Vendor: Red Hat
        Hardware Model: OpenStack Compute
    2. Review the IP addresses of the servera machine.

      [student@servera ~]$ ip addr show
      1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
          link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
          inet 127.0.0.1/8 scope host lo
             valid_lft forever preferred_lft forever
          inet6 ::1/128 scope host
             valid_lft forever preferred_lft forever
      2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
          link/ether 52:54:00:00:fa:0a brd ff:ff:ff:ff:ff:ff
          altname enp0s3
          altname ens3
          inet 172.25.250.10/24 brd 172.25.250.255 scope global noprefixroute eth0
             valid_lft forever preferred_lft forever
          inet6 fe80::5054:ff:fe00:fa0a/64 scope link
             valid_lft forever preferred_lft forever
    3. Exit the servera machine.

      [student@servera ~]$ exit
      logout
      Connection to servera closed.
      [student@workstation ~]$
  3. On the workstation machine, redirect the output of the hostname command to create the machine-name.txt file.

    1. Save the output of the hostname command to the machine-name.txt file.

      [student@workstation ~]$ hostname > machine-name.txt
    2. Verify the content of the machine-name.txt file.

      [student@workstation ~]$ cat machine-name.txt
      workstation.lab.example.com
  4. Copy the machine-name.txt file to the servera machine by using the scp command. Enter student as the password for the servera machine when prompted.

    [student@workstation ~]$ scp machine-name.txt student@servera:~
    student@servera's password: student
    machine-name.txt
  5. Log in to the servera machine and confirm that the machine-name.txt file is successfully copied.

    [student@workstation ~]$ ssh student@servera
    student@servera's password: student
    ...output omitted...
    [student@servera ~]$ cat machine-name.txt
    workstation.lab.example.com
  6. Exit the servera machine.

    [student@servera ~]$ exit
    logout
    Connection to servera closed.
    [student@workstation ~]$

Finish

On the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish network-remote

Revision: rh104-9.1-3d1f2bc