Mac OS利用ssh访问ubuntu虚拟机及免密访问操作
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Mac OS利用ssh访问ubuntu虚拟机及免密访问操作,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2875字,纯文字阅读大概需要5分钟。
内容图文
![Mac OS利用ssh访问ubuntu虚拟机及免密访问操作](/upload/InfoBanner/zyjiaocheng/979/20a791a7d0e841119061fc66f13b9bbe.jpg)
1、将该虚拟机的网口设置成桥接模式(Bridged Adapter),以确保主机可以ping通虚拟机:
2、在ubuntu虚拟机上安装ssh server:
sudo apt-get install openssh-server
3、找到ubuntu的IP地址,即可以通过在terminal输入:
ifconfig
会出现下面的东西:
找到拥有inet的那一行,后面的地址即为该虚拟机的IP地址。这里可以看到,该虚拟机的IP地址为10.66.182.88
4、在主机上同样安装ssh。安装好后为了连接虚拟机,可以进行如下操作:
wubijiadeMacBook-Pro:~ wooka$ ssh wu@10.66.182.88
The authenticity of host '10.66.182.88 (10.66.182.88)' can't be established.
ECDSA key fingerprint is SHA256:xxx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.66.182.88' (ECDSA) to the list of known hosts.
wu@10.66.182.88's password:
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information as of Thu Oct 25 22:23:38 HKT 2018
System load: 0.0 Processes: 109
Usage of /: 17.3% of 8.50GB Users logged in: 1
Memory usage: 6% IP address for eth0: 10.66.182.88
Swap usage: 0%
Graph this data and manage this system at:
https://landscape.canonical.com/
New release '16.04.5 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
Last login: Thu Oct 25 22:23:38 2018 from localhost
wu@ubuntu:~$ ls
这里ssh wu@10.66.182.88
,wu
为虚拟机的用户名
至此可以直接从主机访问虚拟机的文件了。通过输入exit
可退出访问。
wu@ubuntu:~$ exit
logout
Connection to 10.66.182.88 closed.
5、然而,麻烦的是,每次主机访问虚拟机时都要输入密码。如何进行免密操作?
为主机和虚拟机共同建立一个共享的密码。
即,可输入ssh-keygen
,产生一个public/private密码对。
wubijiadeMacBook-Pro:~ wooka$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/wooka/.ssh/id_rsa): y
# 下面一行代表可否用另一个密码代替之前需要输入的密码,为了方便,可以省略直接回车。
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in y.
Your public key has been saved in y.pub.
The key fingerprint is:
SHA256:xxx
wooka@wubijiadeMacBook-Pro.local
The key's randomart image is:
+---[RSA 2048]----+
|.o . o.. .o |
|. + o..... o |
|o..o .o.o.+ |
|=o..+Eo+oo . + |
|o+.oooooS = . |
|..o.. .o . o o |
| o o. . o o |
|. . .o . o |
| . .+ . |
+----[SHA256]-----+
现在,我们将pubilc key推送到虚拟机上,即
ssh-copy-id wu@10.66.182.88
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/wooka/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
wu@10.66.182.88's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'wu@10.66.182.88'"
and check to make sure that only the key(s) you wanted were added.
现在,你控制ubuntu虚拟机的时候,就不需要输入密码了哦!
内容总结
以上是互联网集市为您收集整理的Mac OS利用ssh访问ubuntu虚拟机及免密访问操作全部内容,希望文章能够帮你解决Mac OS利用ssh访问ubuntu虚拟机及免密访问操作所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。