开启两台虚拟机,尝试实现互信

(31条消息) linux ssh互信配置ssh 互信linux凯的博客-CSDN博客

使用ifconfig查看虚拟机的ip
centos:192.168.1.133
Ubuntu:192.168.1.134

内存给太大了,爆满,减少一下每台虚拟机的内存重新开机

都给整成了4G,这看你电脑内存,建议两台虚拟机加起来占的内存为你电脑的1/2

#ssh-keygen       #创建公钥和密钥,会生成id_rsa和id_rsa.pub两个文件
                  #一直回车就行直到生成sha256的图形
                  

#之后在两台机器上互相拷贝公钥
centos:#ssh-copy-id -i  .ssh/id_rsa.pub root@192.168.1.134
ubuntu:#ssh-copy-id -i  .ssh/id_rsa.pub root@192.168.1.133

ubuntu上爆:/usr/bin/ssh-copy-id: ERROR: failed to open ID file '.ssh/id_rsa.pub': No such file

解决这个问题,尝试了升权限,等等还是不行。最后去除文件名,使用引导完成。如下:

root@ubuntu:/# ssh-copy-id -i   root@192.168.1.133
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.1.133 (192.168.1.133)' can't be established.
ECDSA key fingerprint is SHA256:jXPhSEesZ9zVul1/6+mTpt7xNqw/z0XGBtHYRSJ5S7I.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/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
root@192.168.1.133's password: 
Number of key(s) added: 1
​
Now try logging into the machine, with:   "ssh 'root@192.168.1.133'"
and check to make sure that only the key(s) you wanted were added.
​
root@ubuntu:/# ssh 'root@192.168.1.133'
Last login: Wed Aug  2 09:50:28 2023
[root@localhost ~]# cd ~/home/juan
-bash: cd: /root/home/juan: No such file or directory
[root@localhost ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  <font color="#005FFF">下载</font>  <font color="#005FFF">公共</font>  <font color="#005FFF">图片</font>  <font color="#005FFF">文档</font>  <font color="#005FFF">桌面</font>  <font color="#005FFF">模板</font>  <font color="#005FFF">视频</font>  <font color="#005FFF">音乐</font>
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.9.2009 (Core)
Release:    7.9.2009
Codename:   Core
[root@localhost ~]# 

可以看到在ubuntu上已经可以实现免密登录centos了。

在centos上同样的找不到文件的问题

[root@localhost /]# ssh-copy-id -i  root@192.168.1.134
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.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: ERROR: ssh: connect to host 192.168.1.134 port 22: Connection refused

但是变成了ubuntu 134这台机器上22号端口没有开。下面是解决方法

ERROR: ssh: connect to host hdp102 port 22: Connection refused_/usr/bin/ssh-copy-id: error: ssh: connect to host _开着拖拉机回家的博客-CSDN博客

要安装openssh-server

#apt-get install openssh-server    #安装
#systemctl status sshd   #查看openssh是否在运行
​
root@ubuntu:/home/alvaro51/Desktop# systemctl status sshd
 ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2023-08-01 19:40:39 PDT; 1min 32s ago
       Docs: man:sshd(8)
             man:sshd_config(5)
   Main PID: 6712 (sshd)
      Tasks: 1 (limit: 4558)
     Memory: 1.0M
     CGroup: /system.slice/ssh.service
             └─6712 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
Aug 01 19:40:39 ubuntu systemd[1]: Starting OpenBSD Secure Shell server...
Aug 01 19:40:39 ubuntu sshd[6712]: Server listening on 0.0.0.0 port 22.
Aug 01 19:40:39 ubuntu sshd[6712]: Server listening on :: port 22.
Aug 01 19:40:39 ubuntu systemd[1]: Started OpenBSD Secure Shell server.

ubuntu在终端root用户及密码可以正常登陆,但是用ssh登陆,系统却总是提示密码不对

ubuntu登录的密码和su的密码相同但是ssh链接时输入这个密码失败

#在Ubuntu上
​
#vi /etc/ssh/sshd_config    #将PermitRootLogin项改为yes
#service sshd restart       #重启sshd服务

#在centos上
​
[root@localhost /]# ssh-copy-id -i  root@192.168.1.134
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.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
root@192.168.1.134's password: 
​
Number of key(s) added: 1
​
Now try logging into the machine, with:   "ssh 'root@192.168.1.134'"
and check to make sure that only the key(s) you wanted were added.

#在centos上
​
[root@localhost /]# ssh 'root@192.168.1.134'
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.15.0-78-generic x86_64)
​
 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
​
Expanded Security Maintenance for Applications is not enabled.
​
34 updates can be applied immediately.
18 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable
​
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
​
New release '22.04.2 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
​
Your Hardware Enablement Stack (HWE) is supported until April 2025.
Last login: Mon Jul 31 00:50:55 2023
root@ubuntu:~# 
​

可以看到centos上也实现了免密ssh登录Ubuntu

至此两台linux虚拟机之间的互信就完成配置了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值