服务器没有续费,却还想要拥有一个服务器的感觉,所以我就用ssh连接虚拟机,✧(≖ ◡ ≖✿)嘿嘿。
  1. 首先在虚拟机用ifconfig命令查看ip地址,在主机用ping命令其ip地址,看看能否ping通过。

  2. 在虚拟机安装openssh-server,如果是服务器,它是默认安装的,不然你怎么用ssh远程连接服务器嘛。但是自己的安装的linux,默认没有安装。

    1
    sudo apt install openssh-server
  3. 开启ssh服务。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    richie@ubuntu:~$ service sshd start #/restart:重启/stop:停止 /status:状态
    richie@ubuntu:~$ service sshd status
    ● ssh.service - OpenBSD Secure Shell server
    Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
    Active: active (running) since Wed 2018-09-26 08:46:31 PDT; 1min 59s ago
    Main PID: 3121 (sshd)
    CGroup: /system.slice/ssh.service
    └─3121 /usr/sbin/sshd -D

    Sep 26 08:46:31 ubuntu systemd[1]: Starting OpenBSD Secure Shell server...
    Sep 26 08:46:31 ubuntu sshd[3121]: Server listening on 0.0.0.0 port 22.
    Sep 26 08:46:31 ubuntu sshd[3121]: Server listening on :: port 22.
    Sep 26 08:46:31 ubuntu systemd[1]: Started OpenBSD Secure Shell server.
    Sep 26 08:48:25 ubuntu systemd[1]: Started OpenBSD Secure Shell server.

ssh服务开启后,端口22也会默认跟着打开,我们为了确认端口22打开状态可以:

1
2
3
4
5
richie@ubuntu:~$ netstat -ntpl | grep 22
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -

  1. 恭喜你,你已经完成虚拟机的配置了!主机在终端用ssh便可连接。并欺骗自己拥有一台服务器了(狗头)

Comments

2018-09-27
Contents

⬆︎TOP