How you go fit SSH between two Vagrant Linux systems. [Ubuntu and Centos]

ssh.png

My people, your pidgin cloud guy done come again ooo, this time na matter wey concern how to ssh between two vagrant system we wan run so ooo. For this matter so I go assume say you sabi setup vagrant already for your Mac, incase you still no sabi click this Link to show you how you go run am. Windows people abeg no vex for me ooo, na Mac I dey use for my setup.

Oya straight to the matter. Now I go show you how I take arrange my vagrant boxes for my Mac.

  achebe@okechukwus-MacBook-Pro boxes % pwd
  /Users/achebe/Desktop/altschool-cloud-exercises/Exercise One/boxes
  achebe@okechukwus-MacBook-Pro boxes % ls
  centos7            ubuntu_20.04_LTS
  achebe@okechukwus-MacBook-Pro boxes %

For the boxes folder, you go see say I get two vagrant systems; Centos and Ubuntu, na this two system we go try connect together using SSH.

Oya, boot up your two systems using vagrant up, you know how the matter be na. As I run my own, see as e take comot.

Screenshot 2022-08-24 at 21.20.42.png

As you see so, I get Centos system for my left and Ubuntu for my right. Also, I been create the peter and achebeh for the Centos and Ubuntu respectively. You suppose sabi how them they run user creation na. In case you no sabi that one just run this commands.

  # User Creation
  sudo useradd -s /bin/bash -m Peter

  # User Password
  sudo passwd peter  

  # Switch to the created user
  su peter

So we wan ssh from our Ubuntu enter our Centos. Wetin we go do so na to generate the ssh keys from our Centos con share am with the Ubuntu, once we done run am we go fit connect the two systems.

Oya from your Centos system, run this command;

  [peter@localhost ~]$ ssh-keygen -t rsa

Once you done run this command you go see some prompts wey go comot, just the press enter, once e finish you supposed see something like this;

  Generating public/private rsa key pair.
  Enter file in which to save the key (/home/peter/.ssh/id_rsa): 
  Enter passphrase (empty for no passphrase): 
  Enter same passphrase again: 
  Your identification has been saved in /home/peter/.ssh/id_rsa.
  Your public key has been saved in /home/peter/.ssh/id_rsa.pub.
  The key fingerprint is:
  SHA256:h/ErRSAuDhLFSTqwjqEpNJCm1lMpqQMf0goDJB73t8Y peter@localhost.localdomain
  The key's randomart image is:
  +---[RSA 2048]----+
  |OOoo. o .        |
  |@=Bo.+ . .       |
  |@O+.+.... .      |
  |BOo= .o .=       |
  |*.. o  ES +      |
  |.     .  o .     |
  |        . .      |
  |         .       |
  |                 |
  +----[SHA256]-----+

After you done run that command, some files suppose show for the ./ssh folder. This files na the private and public keys wey the ssh-keygen -t rsa command create. When you run this command you suppose see wetin I dey talk.

[peter@localhost ~]$ ls .ssh/

The id_rsa file na the private key while id_rsa.pub na the public key.

The next matter we go run now na to transfer this our public key from our Centos go the Ubuntu machine. To run this matter, run this command from your Centos machine.

  [peter@localhost ~]$ ssh-copy-id -i .ssh/id_rsa achebeh@192.168.56.8

If you dey wonder where I get 192.168.56.8 from, this na the IP address of my Ubuntu machine, once you run ifconfig from your Ubuntu machine, you go see the IP address. After I run the command, one prompt go comot, type yes and e go also ask for the password of the user logged in for the Ubuntu, for my case na achebeh be the user. I dey use God beg you, no go put wrong password ooo. You suppose see something like this from your end when you done try am.

  /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: ".ssh/id_rsa.pub"
  The authenticity of host '192.168.56.8 (192.168.56.8)' can't be established.
  ECDSA key fingerprint is SHA256:lT1aQ9iTANy/fBHQ7GuFhHa64rIcaMhsh3qm676FL+4.
  ECDSA key fingerprint is MD5:9a:49:a9:34:b8:8b:12:6d:e8:8c:b2:c3:da:b8:75:ab.
  Are you sure you want to continue connecting (yes/no)? yes
  /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
  /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
  achebeh@192.168.56.8's password: 

  Number of key(s) added: 1

  Now try logging into the machine, with:   "ssh 'achebeh@192.168.56.8'"
  and check to make sure that only the key(s) you wanted were added.

Once you done run am, make we cross check if na the correct public key enter the Ubuntu machine from the Centos.

Oya from your Centos machine run this command;

  [peter@localhost ~]$ cat .ssh/id_rsa.pub

For your Ubuntu machine run this command;

  achebeh@ubuntu-focal:~$ cat .ssh/authorized_keys

The output of the command na the same thing. For my own see wetin I get.

  ssh-rsa     AAAAB3NzaC1yc2EAAAADAQABAAABAQDADtpjI0VCo/VP5mcjLkvJZKCN3NaryGByXBbKfuxj5tocJ0wQ5zIg6c2qF3hLFWMdF1+w6Qx3TDmlNnlKP18Ir8MNsALWumafCkBqXpmeAniJeWGJMUbGcRe8Swt+DetCAzeTyumw3D6AKkt5B/XlZBpl3psukF9y/7qsh1KA6zkIRyDZMDDUWU3/Cm1gjmy0LCciYvyEXVmYfOX2VAt1Y4pc1LTeIygHTo+9a5d4L5FOjxNEhm9jfTzbJcn4/UyIuaAZ36pSSia/n2vaBP1srvDE0I58a+pVz1fiWWSIKcx/xhhaWxmAiJBckA5aRlG8oJaLvlQfWUTrmoPsblbx peter@localhost.localdomain

Oya make we test wetin we done do. From your Centos machine run this command;

  ssh achebeh@192.168.56.8

You suppose see something like this;

  [peter@localhost ~]$ ssh achebeh@192.168.56.8
  Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0-122-generic x86_64)

   * Documentation:  https://help.ubuntu.com
   * Management:     https://landscape.canonical.com
   * Support:        https://ubuntu.com/advantage

    System information as of Wed Aug 24 21:32:22 UTC 2022

    System load:  0.0               Processes:               134
    Usage of /:   5.1% of 38.70GB   Users logged in:         1
    Memory usage: 27%               IPv4 address for enp0s3: 10.0.2.15
    Swap usage:   0%                IPv4 address for enp0s8: 192.168.56.8

   * Super-optimized for small spaces - read how we shrank the memory
     footprint of MicroK8s to make it the smallest full K8s around.

     https://ubuntu.com/blog/microk8s-memory-optimisation

  11 updates can be applied immediately.
  10 of these updates are standard security updates.
  To see these additional updates run: apt list --upgradable

  New release '22.04.1 LTS' available.
  Run 'do-release-upgrade' to upgrade to it.


  achebeh@ubuntu-focal:~$

Once you done reach this stage, my people you done finish be that ooo. As e dey so the two systems done dey connected like so.