Hello, this is for my Intro to Linux class. We are using BASH and Vi editor. Tha
ID: 3604853 • Letter: H
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 (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 don’t 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.
Explanation / Answer
===============
Goto home directory:-
---------------------
ss139t@ubuntu:~$ pwd
/home/ss139t
ss139t@ubuntu:~$
CHECK .ssh directory is present by giving below commmad:
--------------------------------
ss139t@ubuntu:~$ ls -altrd .ssh
drwxrwxr-x 2 ss139t ss139t 4096 Jul 29 11:06 .ssh
change persmission:-
---------------------
ss139t@ubuntu:~$ ls -altrd .ssh
drwxrwxr-x 2 ss139t ss139t 4096 Jul 29 11:06 .ssh
ss139t@ubuntu:~$ chmod 700 .ssh
ss139t@ubuntu:~$ ls -altrd .ssh
drwx------ 2 ss139t ss139t 4096 Jul 29 11:06 .ssh
ss139t@ubuntu:~$
-----------------------
ss139t@ubuntu:~/.ssh$ pwd
/home/ss139t/.ssh
ss139t@ubuntu:~/.ssh$ touch authorized_keys
ss139t@ubuntu:~/.ssh$ ls -ltr
total 0
-rw-rw-r-- 1 ss139t ss139t 0 Oct 30 10:27 authorized_keys
ss139t@ubuntu:~/.ssh$
--------------
ss139t@ubuntu:~/.ssh$ which ssh-keygen
/usr/bin/ssh-keygen
ss139t@ubuntu:~/.ssh$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ss139t/.ssh/id_rsa): id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
SHA256:CfwltSVzxNGCvrHNYFz/TTH7xNq3Ca6plTnUcDGb1iY ss139t@ubuntu
The key's randomart image is:
+---[RSA 2048]----+
| ++== |
| . ..*+ Bo |
| o .ooo E ++|
| o +* = +.+|
| S. O . *o|
| + =.. *|
| =. . +|
| . o. o |
| ..o. |
+----[SHA256]-----+
ss139t@ubuntu:~/.ssh$ ls -ltr
total 8
-rw-rw-r-- 1 ss139t ss139t 0 Oct 30 10:27 authorized_keys
-rw-r--r-- 1 ss139t ss139t 395 Oct 30 10:31 id_rsa.pub
-rw------- 1 ss139t ss139t 1675 Oct 30 10:31 id_rsa
ss139t@ubuntu:~/.ssh$
-------------------------
cat ~/.ssh/id_rsa.pub | ssh jd-cit160a.ecs.csun.edu `cat >> ~/.ssh/authorized_keys`
-------------
ss139t@ubuntu:~/.ssh$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBPMWoOPYfi+N6CXu+YepIeB3vH6nKXnCfYuUiPbnAf+acvbaCQf5bDnTcaASh0HYW4EgiP+/ktgSy7mPnTATP/qMboBP0B+PiF2v1TCi4cmv4jofPCs7LZTQdy8wfsX8jCuwwHF55ag4Z0LldFIhtlDVUQa6lEDzhj9KX7d0t8yral+2fkCVyAaJ2wlBzlhWNSkby4q1XzZ4BXqZpOKvQBjJth01fiISo8BVwNVbjN07cZVJvdwrRO/uby231kwTKCo2G7kbfayq9TrwSrd0TjYhaqpSrQmoGNkzyVettxQvuoX7S1yJLUKLeirxsa9WCZwSyRvWj1NfT8QVHcat/ ss139t@ubuntu
===
Using username "ss139t".
Authenticating with public key "rsa-key-20150313"
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-62-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
169 packages can be updated.
73 updates are security updates.
Last login: Mon Oct 30 10:28:16 2017 from 10.0.2.2
ss139t@ubuntu:~$
==============
IT WILL LOGIN WITHOUT PASSWORD
==
Please read step by step process.
====
Thanks
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.