Question: Hello, this is for my Intro to Linux class. We are using BASH and Vi editor. Thank you in advance! STAGE 4 | SSH Keys
Hello, this is for my Intro to Linux class. We are using BASH and Vi editor. Thank you in advance!
STAGE 4 | SSH Keys (Server Side) Perform the following functions on the computer in which you want to log into. For the purpose
of this lab section, these steps will be performed on the CIT 160 lab environment server.
1. Create a .ssh directory inside your home directory (It may already exist) 2. Change the permissions of the .ssh directory to be rwx------ (Hint: You should use numerical
values to set the permissions) 3. Create (by using the touch command) an empty file in the .ssh directory called
authorized_keys.
The authorized_keys file is a known file by ssh. This means that ssh will look for this file in your home directory when you are connecting to the environment. This file must be named as-is. Any name differences and ssh will not know what it is thus ignoring the file.
This file will contain a list of Public Keys in which you authorize to log into your account on the CIT 160 lab environment.
STAGE 5 | S SH Keys (Client Side) For this stage we will use the CSUN SSH server. Go ahead and log-out of the CIT 160 lab
environment. 4. SSH into ssh.csun.edu using a newly opened terminal
We will now run a script called ssh-keygen. This will generate both a public and private key. When prompted with Enter file in which to save the key, leave it blank (Just press the Enter key). Do the same for when it prompts you to enter a passphrase.
Before running the ssh-keygen command, you should always check to make sure that you will run the legitimate version of the command. You dont want to run a rogue version because this may lead to someone stealing your credentials. To check which ssh-keygen command you will run, we will use the which command. This command will echo out the full directory path to the command that the system will run.
5. Run the which command as follows $ which ssh-keygen
The above command should echo out the following directory path: /usr/bin/ssh-keygen If it does not echo out the above directory path, let Josh know immediately.
6. Once we confirm that we are running the legitimate ssh-keygen command, run the command as follows
$ ssh-keygen Remember to follow the instructions stated before step 5 when running this command.
7. Before we move on, try logging into the CIT 160 Lab Environment from the CSUN SSH server. Do not actually login. Notice how it prompted you for your password. Cancel this login attempt (ctrl + c)
8. Append your new public key to the end of the authorized_keys file on the CIT 160 lab Environment using the following command
cat ~/.ssh/id_rsa.pub | ssh jd-cit160a.ecs.csun.edu cat >>
~/.ssh/authorized_keys
The above command does the following: cat ~/.ssh/id_rsa.pub | This will cat out the contents in ~/.ssh/id_rsa.pub and pipe it into what follows the | (pipe). ssh jd-cit160a.ecs.csun.edu This will ssh into the CIT 160 lab environment cat >> ~/.ssh/authorized_keys This will run the cat command on the CIT 160 lab environment. It will cat out what was piped into the ssh command (in this case the ~/.ssh/id_rsa.pub) and append it to ~/.ssh/authorized_keys on the CIT 160 lab environment. Once the command finishes, it will exit the CIT 160 lab environment and return you to the CSUN SSH server.
Everything to the right of the | (pipe) is how you would run a command on a remote server. This will ssh into the remote server, execute the command, and return you back to the environment you were originally in. Wrapping the command to run in quotes is not required but it is recommended. This is because when you want to run multiple items at once, you will need to wrap it in quotes. Otherwise, the first command will run on the remote server while any other following commands will run on your original server.
9. Now try to ssh into the CIT 160 lab environment. You should be able to login without providing your password.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
