In this exercise, you will log into a remote system as different users and execute commands.
Outcomes
You should be able to:
Log in to a remote system.
Execute commands with the OpenSSH secure shell.
Log in to workstation as student using student as the password.
On workstation, run lab ssh-access start to start the exercise.
This script ensures that the environment is setup correctly.
[student@workstation ~]$lab ssh-access start
From workstation, open an SSH session to servera as student.
[student@workstation ~]$ssh student@servera...output omitted...[student@servera ~]$
Open an SSH session to serverb as student.
Accept the host key.
Use student as the password when prompted for the password of the student user on serverb.
[student@servera ~]$ssh student@serverbThe authenticity of host 'serverb (172.25.250.11)' can't be established. ECDSA key fingerprint is SHA256:ERTdjooOIrIwVSZQnqD5or+JbXfidg0udb3DXBuHWzA.Are you sure you want to continue connecting (yes/no)?yesWarning: Permanently added 'serverb,172.25.250.11' (ECDSA) to the list of known hosts.student@serverb's password:student...output omitted...[student@serverb ~]$
The host key is recorded in the /home/student/.ssh/known_hosts file on servera to identify serverb because the student user has initiated the SSH connection from servera.
If the /home/student/.ssh/known_hosts file does not already exist, it comes into existence as a new file along with the new entry in it.
The ssh command fails to execute properly if the remote host appears to have a different key than the recorded key.
Run the w command to display the users that are currently logged in to serverb.
[student@serverb ~]$w18:49:29 up 2:55, 1 user, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATstudentpts/0172.25.250.1018:33 0.00s 0.01s 0.00s w
The preceding output indicates that the student user has logged in to the system from the host with an IP address of 172.25.250.10 which is servera in the classroom network.
The IP address of a system identifies the system on a network. You are going to learn about IP addresses in the later chapter.
Exit the student user's shell on serverb.
[student@serverb ~]$exitlogout Connection to serverb closed.[student@servera ~]$
Open an SSH session to serverb as root.
Use redhat as the password of the root user.
[student@servera ~]$ssh root@serverbroot@serverb's password:redhat...output omitted...[root@serverb ~]#
Notice that the preceding ssh command did not ask you to accept the host key because it was found among the known hosts.
Should the identity of serverb change at any time, OpenSSH prompts you to verify and accept the new host key.
Run the w command to display the users that are currently logged in to serverb.
[root@serverb ~]#w19:10:28 up 3:16, 1 user, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATrootpts/0172.25.250.1019:09 1.00s 0.01s 0.00s w
The preceding output indicates that the root user has logged in to the system from the host with an IP address of 172.25.250.10 which is servera in the classroom network.
Exit the root user's shell on serverb.
[root@serverb ~]#exitlogout Connection to serverb closed.[student@servera ~]$
Remove the /home/student/.ssh/known_hosts file from servera.
This causes ssh to lose the recorded identities of the remote systems.
[student@servera ~]$rm /home/student/.ssh/known_hosts
Host keys can change for legitimate reasons: perhaps the remote machine was replaced because of a hardware failure, or perhaps the remote machine was reinstalled.
Usually, it is advisable only to remove the key entry for the particular host in the known_hosts file.
Since this particular known_hosts file has only one entry, you can remove the entire file.
Open an SSH session to serverb as student.
Accept the host key if asked.
Use student as the password when prompted for the password of the student user on serverb.
[student@servera ~]$ssh student@serverbThe authenticity of host 'serverb (172.25.250.11)' can't be established. ECDSA key fingerprint is SHA256:ERTdjooOIrIwVSZQnqD5or+JbXfidg0udb3DXBuHWzA.Are you sure you want to continue connecting (yes/no)?yesWarning: Permanently added 'serverb,172.25.250.11' (ECDSA) to the list of known hosts.student@serverb's password:student...output omitted...[student@serverb ~]$
Notice that the ssh command asked for your confirmation to accept or reject the host key because it could not find one for the remote host.
Exit the student user's shell on serverb and confirm that a new instance of known_hosts exists on servera.
[student@serverb ~]$exitlogout Connection to serverb closed.[student@servera ~]$ls -l /home/student/.ssh/known_hosts-rw-r--r--. 1 student student 183 Feb 1 20:26 /home/student/.ssh/known_hosts
Confirm that the new instance of known_hosts file has the host key of serverb.
[student@servera ~]$cat /home/student/.ssh/known_hostsserverb,172.25.250.11 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBI9LEYEhwmU1rNqnbBPukH2Ba0/QBAu9WbS4m03B3MIhhXWKFFNa/UlNjY8NDpEM+hkJe/GmnkcEYMLbCfd9nMA=
Actual output will vary.
Run hostname remotely on serverb without accessing the interactive shell.
[student@servera ~]$ssh student@serverb hostnamestudent@serverb's password:studentserverb.lab.example.com
The preceding command displayed the full hostname of the remote system serverb.
Exit the student user's shell on servera.
[student@servera ~]$exitlogout Connection to servera closed.