First Learn some terminologies:
- Host = your machine
- Guest = your VM
Creating SSH connection from Host to guest
Step 1: Install SSH into both your host and guest (vm)
sudo pacman -S ssh
for archsudo dnf install sshd
for rhel based distrossudo apt install ssh
for debian based distros
Step 2: Make sure ssh service is running
- check via
systemctl status ssh
- It should be showing
active
andrunning
- If not start using
systemctl enable ssh && systemctl start ssh
Step 3: Make sure port 22 is listening
lsof -i -P -n | grep LISTEN
- It should be showing
LISTEN
on ssh and port 22
Step 4: Configure Network Setting of VM
- Goto VM’s network setting and set network Attached to NAT
- and click on Advanced and Open port forwarding and set it like below
Name | Protocol | Host IP | Host Port | Guest IP | Guest Port |
---|---|---|---|---|---|
ssh | TCP | - | 2222 | - | 22 |
Step 5: Connect to VM’s SSH from your host
- on your host open command prompt/powershell or terminal and
- type:
ssh -p 2222 username@localhost
How to connect to your Guest (VM) SSH from another computer
Step 1:
- Make VM’s network setting “Attached to Bridged”
Step 2:
- Note the IP of your VM using
ip a
Step 3:
- Connect from another computer
- In another computer type this command
ssh username@ip-of-your-vm
ssh user@192.168.1.10
Notice this only works when both computers are connected in same network via wifi or LAN.