---
# System prepended metadata

title: VM virtual box ssh 連線
tags: [Linux]

---

# VM virtual box ssh connection


1. select 'file', 'tools', 'net adminstrator'
![](https://hackmd.io/_uploads/SJ_2msLWp.png)
2. set another IP. (an IP already exists)
![](https://hackmd.io/_uploads/ryP-Ns8Wa.png)
3. Do command `ipconfig` on Windows cmd to check virtual box network is online and get the IP.
![](https://hackmd.io/_uploads/HkX34sLZa.png)
4. Do command `ifconfig` on Linux server to get server IP.
![](https://hackmd.io/_uploads/HkBSBjIZp.png)
5. Click 'setting' on your virtual machine.
![](https://hackmd.io/_uploads/rJz9SiI-a.png)
6. Open 'Network', unfold 'Advance Setting', click 'Port Forwarding'
![](https://hackmd.io/_uploads/H1J7vsLW6.png)
7. Click the bottom on the right side to add a new IP.
![](https://hackmd.io/_uploads/SJvq8iL-T.png)
8. Set the parameters. Nameing your connection, host IP is your windows IP from step 3, and guest IP is from your server.
![](https://hackmd.io/_uploads/rJMkDoLWT.png)
9. On your server, try to do the command `sudo service ssh status`, if the ssh tools have not being installed, please install the tools via these instructions:
![](https://hackmd.io/_uploads/r1QSOo8Wa.png)
```linux=
sudo apt-get update
sudo apt-get install openssh-server -y
```
10. If the ssh tools have already being installed properly, enable the ssh service.
![](https://hackmd.io/_uploads/HkT3Oj8Wa.png)

11. Connecting to the server.
![](https://hackmd.io/_uploads/H1Qb3sIWT.png)
Successfully connecting to the server.

## If using vscode and the ip had been used before
* Delete old ssh setting
    * C:\Users\$(username)\.ssh
    * Delete `known_hosts` and `known_hosts.old`