In this lab, students will log into a remote system as different users and execute commands.
Outcomes
Students will log into a remote system and execute commands with the OpenSSH secure shell.
Log in as student on your desktopX machine.
ssh to your serverX machine. Accept the host
key if asked. The host key is recorded on our local machine to identify the remote machine. The ssh command will fail to execute properly if the remote ssh host appears to have a different key than the recorded host key. The host key records are stored in the known_hosts file in the .ssh directory in the user's home directory on the local system.
[student@desktopX ~]$ssh student@serverXThe authenticity of host 'serverX (172.25.X.11)' can't be established. ECDSA key fingerprint is 47:bf:82:cd:fa:68:06:ee:d8:83:03:1a:bb:29:14:a3. Are you sure you want to continue connecting (yes/no)? yes student@serverX's password:student
Run the w command. The output of the w clearly indicates we have logged in as user student from desktopX.
[student@serverX ~]$w -f11:01:23 up 1 day, 19:10, 1 user, load average: 0,0,0 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT student pts/1 desktopX 11:01 0.00s 0.12s 0.09s w
Execute the exit command to terminate the secure shell connection.
[student@serverX ~]$exit[student@desktopX ~]$
This time, ssh to your serverX machine as user root.
[student@desktopX ~]$ssh root@serverXroot@serverX's password:redhat[root@serverX ~]#
Run the w command again. This time, the output of the w shows the active connection to the root user account from desktopX.
[root@serverX ~]#w -f11:01:23 up 1 day, 19:10, 1 user, load average: 0,0,0 USER TTY FROM LOGIN@ IDLE JCPU PCPU root pts/2 desktopX 11:09 0.00s 0.13s 0.08s w
Run the exit to terminate the secure shell connection.
[root@serverX ~]#exit[student@desktopX ~]$
There are different reasons why a remote host might have legitimately changed its host key. One common reason is when the remote machine is replaced because of hardware failure, or reinstalled. Usually, it is advisable to only remove the key entry for the particular host in the known_hosts. In this case, there is only one host entry in the known_hosts, so it can be removed completely. Remove the known_hosts file for the user student.
[student@desktopX ~]$rm ~/.ssh/known_hosts
ssh to serverX as root again. Accept the key, log in, and then exit the session.
[student@desktopX ~]$ssh root@serverXThe authenticity of host 'serverX (::1)' can't be established. ECDSA key fingerprint is 47:bf:82:cd:fa:68:06:ee:d8:83:03:1a:bb:29:14:a3. Are you sure you want to continue connecting (yes/no)? yes root@serverX's password:redhat[root@serverX ~]#exit[student@desktopX ~]$
Use ssh non-interactively to run the
hostname command on serverX as root.
[student@desktopX ~]$ssh root@serverX hostnameroot@serverX's password:redhatserverX.example.com