How to: Connect from one machine to another using SSH (Vagrant)

How to: Connect from one machine to another using SSH (Vagrant)

Table of contents

No heading

No headings in the article.

Connecting from one machine to another using SSH (Secure Shell) is of great importance, especially when working with tools like Vagrant. SSH provides a secure and encrypted channel for communication between machines over an insecure network, such as the Internet.

SSH plays a crucial role in connecting from one machine to another when using Vagrant. Its security features, remote access capabilities, command execution, file transfer mechanisms, and port forwarding support make SSH an essential tool for managing and interacting with virtual machines and remote environments.

To connect from one machine to the other, ensure Vagrant machines are up and running. If you haven't started them yet, navigate to their respective directories with the Vagrantfiles and run /vagrant up for each machine.

First,you might want to run /vagrant global-status to know the machine you have running. Here is the list of machines I currently have running on my pc.

Note the machines you want to connect then ssh into any of them using either /vagrant ssh "your machine id", or "vagrant ssh your machine name". I will be using two of my machines- “lagosMaster” and “ibadan”.

As seen below, I used vagrant ssh lagosMaster which is the name

The first thing to do is to generate an ssh key to serve as an access key to the machine. To achieve this, type ssh-keygen or do /ls -al ~/.ssh to check if you have created one in the past to avoid duplicates.

Then log into your other machine and edit your config file to allow password authentication using your preferred editor, Nano or Vim works perfectly. I prefer nano so I will be running /sudo nano /etc/ssh/sshd_config. Then scroll down, and change password authentication from “no” to “yes”. By default, you will see this:

Change to this

Then save the file and run /sudo systemctl restart sshd to restart the machine sshd.

Go back to your first machine and run /ssh-copy-id -i vagrant@(add the IP address of the machine you want to ssh into). You can run /ifconfig command to know the IP address of the machine.

Run /ssh-copy-id -i vagrant@your IP Address to copy it into your machine then ssh into your target machine using ssh vagrant@your IP address.

Congrats, you have successfully connected from one machine to another using SSH (Vagrant). Kindly follow me for more content on cloud engineering, gracias.