> For the complete documentation index, see [llms.txt](https://davids-tutorials.gitbook.io/robotics/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://davids-tutorials.gitbook.io/robotics/ignore-extra/cyber.md).

# Cyber

> First complete Lab, then Project

> [wget](https://www.gnu.org/software/wget/) (short for "web-get")&#x20;

### Tree Command (Alternative to ls)

```
sudo apt-get install tree
```

```
tree <folder>
```

```
#############
#  OUTPUT:  #
#############

/home
└── folder
    ├── unit2
    ├── unit3
    │   ├── cp_leak.txt
    │   └── crackfiles.zip
    └── unit6
        ├── attrib.txt
        ├── cat.jpg
        ├── dog.jpg
```

PRE-REQ

* [ ] &#x20;[CYB101 Setup Scripts zip](https://github.com/codepath/cyb101-vm-setup/archive/refs/heads/main.zip) into the `~` directory on your VM so that `~/Scripts` and `~/Files` are valid paths.
* [ ] From the `~` directory, run `./Scripts/setup.sh`
  * If you run into issues, try looking through the Scripts and only run the ones you need for the unit you're trying to complete (e.g., `Scripts/unit3_lab.sh`)
  * More guidance can be found on the repo [README](https://github.com/codepath/cyb101-vm-setup).
    * [ ] &#x20;[CYB101 Setup Scripts zip](https://github.com/codepath/cyb101-vm-setup/archive/refs/heads/main.zip) into the `~` directory on your VM so that `~/Scripts` and `~/Files` are valid paths.
    * [ ] From the `~` directory, run `./Scripts/setup.sh`
      * If you run into issues, try looking through the Scripts and only run the ones you need for the unit you're trying to complete (e.g., `Scripts/unit3_lab.sh`)
      * More guidance can be found on the repo [README](https://github.com/codepath/cyb101-vm-setup)
      * Once you get the `"All scripts executed successfully."` message, you're ready to start the course!

## Project Part: SSH Keys

```
ssh-keygen -t rsa -b 4096 -C "CYB Ubuntu Key"
```

* &#x20;4096-bit SSH RSA public and private keys.
* **Commands breakdown:**
  * `ssh-keygen` = the utility used to generate the key pair
  * `-t rsa` = specifies the **t**ype of key to create (e.g., rsa)
  * `-C "CYB Ubuntu Key"` = provides custom key comment (which will be appended at the end of the public key).
    * Usually an email address is used as a comment, but this time we're labeling it with the machine we'll use it on.
    * Think of it like a label for your key, so you don't mix it up with other keys!

```
Enter file in which to save the key 
(/home/codepath/.ssh/id_rsa): 
/home/codepath/.ssh/id_rsa_cyb

## No Passphrase
```

* Public key is .pub
* Private key is no extension or .pem

#### View keys

```
cat ~/.ssh/id_rsa_cyb101 
#### OUTPUT ####
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAACFwAAAAdzc2gtcn

cat ~/.ssh/id_rsa_cyb101.pub      
#### OUTPUT ####
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC5OSa7cKQQg4rWohWVYobfVUhilcojgydrxTOtzRDrYm/W+K1QrndFjxL6CH9JTFPapqkZDk92lDXvrn+qQKNaBkzNDjTyTKJp2cLd5eGIax2CWdSqgZhtjo+kAeB2wnEPU6C2rPqw5EVveATYoPfUBVTtfZt2PsxZGAVp
#### OUTPUT ####
QbFREW0tL05V8T2YHBtvoCeoSlQ1NjMLWvKQ== CYB101 Ubuntu Key
```

> 3 main uses of keys: authentication, encryption integrity

#### Using ssh to connect to remote server

```
## Example:
ssh -p XXXX -i ~/.ssh/id_rsa_cyb101 codepath@lab-xxxxx.eastus.cloudapp.azure.com
```

#### Stuck on this part (might not need):

```
ssh-copy-id codepath@localhost
```

* ```
  Their user@domanin: codepath@lab000001
  ```

## Part 3: Encryption with SSH Keys

Assymetric encryption:\
\- Public key: encrypt\
\- Private key: decrypt

```
openssl genrsa -out ~/.ssh/privatekey.pem 2048
```

\- creates private.pem file (longer file)

```
openssl rsa -in  ~/.ssh/privatekey.pem -out ~/.ssh/publickey.pem -pubout -outform PEM
```

\- creates publickey.pem file (shorter file)

```
echo "MY SECRET MESSAGE" > secret.txt
cat secret.txt
```

\- creates file & display, this is final step to setup

```
openssl pkeyutl -encrypt -pubin -inkey ~/.ssh/publickey.pem -in secret.txt -out secret.txt.encrypted 
```

\- this encrypts our secret msg with public&#x20;

```
cat secret.txt.encrypted
```

\- to view file

```
openssl pkeyutl -decrypt -inkey  ~/.ssh/privatekey.pem -in secret.txt.encrypted  -out secret.txt.decrypted 

```

\- generate decrypted file

```
cat secret.txt.decrypted
```

<figure><img src="/files/d8sa0ubcXRVbsj7D9Can" alt=""><figcaption></figcaption></figure>
