Red Hat System Administration I
Log in to a remote system as different users and execute commands.
Outcomes
Log in to a remote system.
Execute commands with the OpenSSH secure shell.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start ssh-access
Instructions
From
workstation, open an SSH session to theserveramachine as thestudentuser.[student@workstation ~]$
ssh student@servera[student@servera ~]$Open an SSH session to the
serverbmachine as thestudentuser. Accept the host key. Usestudentas the password when prompted for the password of thestudentuser on theserverbmachine.[student@servera ~]$
ssh student@serverbThe authenticity of host 'serverb (172.25.250.11)' can't be established. ED25519 key fingerprint is SHA256:h/hEJa/anxp6AP7BmB5azIPVbPNqieh0oKi4KWOTK80. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])?yesWarning: Permanently added 'serverb' (ED25519) to the list of known hosts. student@serverb's password:student...output omitted... [student@serverb ~]$The
sshcommand records the host key on the/home/student/.ssh/known_hostsfile in theserveramachine to identify theserverbmachine. Thestudentuser initiated the SSH connection from theserveramachine. If the/home/student/.ssh/known_hostsfile does not exist, then it is created along with the new entry in it. Thesshcommand fails to execute correctly if the remote host appears to have a different key from the recorded key.Display the users that are currently logged in to the
serverbmachine. Thestudentuser is logged in to the system from the host with an IP address of172.25.250.10, which is theserveramachine in the classroom network.[student@serverb ~]$
w --from03:39:04 up 16 min, 1 user, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATstudentpts/0 172.25.250.10 20:40 1.00s 0.01s 0.00s w --fromExit the
studentuser's shell on theserverbmachine.[student@serverb ~]$
exitlogout Connection to serverb closed. [student@servera ~]$Open an SSH session to the
serverbmachine as therootuser. Useredhatas the password of therootuser. The command did not ask you to accept the host key, because it was found among the known hosts. If the identity of theserverbmachine changes, then OpenSSH prompts you to challenge the new host key.[student@servera ~]$
ssh root@serverbroot@serverb's password:redhat...output omitted... [root@serverb ~]#Run the
wcommand to display the users that are currently logged in to theserverbmachine. The output indicates that therootuser is logged in to the system from the host with an IP address of172.25.250.10, which is theserveramachine in the classroom network.[root@serverb ~]#
w --from03:46:05 up 23 min, 1 user, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATrootpts/0172.25.250.1020:44 1.00s 0.02s 0.00s w --fromExit the
rootuser's shell on theserverbmachine.[root@serverb ~]#
exitlogout Connection to serverb closed. [student@servera ~]$Remove the
/home/student/.ssh/known_hostsfile from theserveramachine. This operation causessshto lose the recorded identities of the remote systems.[student@servera ~]$
rm /home/student/.ssh/known_hostsHost keys can change for legitimate reasons: perhaps the remote machine was replaced because of a hardware failure, or the remote machine was reinstalled. Usually, it is advisable to remove the key entry only for the particular host in the
known_hostsfile. Because this particularknown_hostsfile has only one entry, you can remove the entire file.Open an SSH session to the
serverbmachine as thestudentuser. If asked, accept the host key. Usestudentwhen prompted for the password of thestudentuser on theserverbmachine.[student@servera ~]$
ssh student@serverbThe authenticity of host 'serverb (172.25.250.11)' can't be established. ED25519 key fingerprint is SHA256:h/hEJa/anxp6AP7BmB5azIPVbPNqieh0oKi4KWOTK80. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])?yesWarning: Permanently added 'serverb' (ED25519) to the list of known hosts. student@serverb's password:student...output omitted... [student@serverb ~]$The
sshcommand asked for your confirmation to accept or reject the host key, because it could not find one for the remote host.Exit the
studentuser's shell on theserverbmachine, and confirm that a new instance of theknown_hostsfile exists on theserveramachine.[student@serverb ~]$
exitlogout Connection to serverb closed. [student@servera ~]$ls -l /home/student/.ssh/known_hosts-rw-------. 1 student student 819 Mar 24 03:47 /home/student/.ssh/known_hostsConfirm that the new instance of the
known_hostsfile has the host key of theserverbmachine. The following command output is an example; yourworkstationoutput might differ.[student@servera ~]$
cat /home/student/.ssh/known_hosts...output omitted... serverb ecdsa-sha2-nistp256 AAAAB3NzaC1yc2EAAAADAQ... ...output omitted...Run the
hostnamecommand remotely on theserverbmachine without accessing the interactive shell.[student@servera ~]$
ssh student@serverb hostnamestudent@serverb's password:studentserverb.lab.example.comReturn to the
workstationsystem as thestudentuser.[student@servera ~]$
exitlogout Connection to servera closed.