MacOSX 终端连接虚拟机

首先在虚拟机终端输入ifconfig找到ip地址:
在这里插入图片描述

然后打开mac终端输入:

:ssh [email protected]

显示结果为:

ssh: connect to host 172.16.241.137 port 22: Connection refused

为什么拒绝呢?因为可能没开服务,也有可能是端口问题。

先去看看虚拟机的ssh服务。

检查SSH服务有没有开启。使用命令:sudo ps -e | grep ssh来查看:
在这里插入图片描述

没有SSH服务,试着开启SSH服务。使用命令sudo /etc/init.d/ssh start来开启服务:
在这里插入图片描述
文件不存在,说明没有安装 SSH 服务。

此时需要安装 SSH服务,为了能提高安装成功率,建议先更新源:sudo apt-get update更新安装源,如图:
在这里插入图片描述

安装SSH服务,使用命令:sudo apt-get install openssh-server:
在这里插入图片描述
等待安装结束即可。然后再次查看服务有没有启动:sudo ps -e | grep ssh:
在这里插入图片描述
检查到sshd,这就说明 SSH 服务启动了。如果需要再次确认或者没有图中的结果,使用命令来启动:sudo /etc/init.d/ssh start。

有几条命令:

  • sudo service ssh status 查看服务状态:
    在这里插入图片描述
  • sudo service ssh stop 关闭服务:
    在这里插入图片描述
  • sudo service ssh start 开启服务:
    在这里插入图片描述
  • sudo service ssh restart 开启服务:
    在这里插入图片描述

下面就可以开始mac终端登录虚拟机了。

扫描二维码关注公众号,回复: 9658321 查看本文章

输入ssh [email protected]

:ssh [email protected]
The authenticity of host '172.16.241.137 (172.16.241.137)' can't be established.
ECDSA key fingerprint is SHA256:t4gskNBu8ScuhmstQfWF5pZdf924f3Qyc9tJ1jk0f2Q.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.241.137' (ECDSA) to the list of known hosts.
[email protected]'s password: 
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-88-generic x86_64)

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

  System information as of Thu Mar  5 18:06:08 UTC 2020

  System load:  0.19               Processes:            168
  Usage of /:   21.3% of 19.56GB   Users logged in:      1
  Memory usage: 35%                IP address for ens33: 172.16.241.137
  Swap usage:   0%

 * Multipass 1.0 is out! Get Ubuntu VMs on demand on your Linux, Windows or
   Mac. Supports cloud-init for fast, local, cloud devops simulation.

     https://multipass.run/

 * Latest Kubernetes 1.18 beta is now available for your laptop, NUC, cloud
   instance or Raspberry Pi, with automatic updates to the final GA release.

     sudo snap install microk8s --channel=1.18/beta --classic

14 packages can be updated.
0 updates are security updates.


Last login: Thu Mar  5 16:45:56 2020
zhaolu@zhaolucom:~$ 

暂时完了。

发布了78 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/LU_ZHAO/article/details/104687951