三台centos 一台服务器192.168.2.152 一台客户端192.168.2.142 一台客户端192.168.2.151

(1)产生无密钥

[root@localhost ~]#  ssh-keygen -t dsa

Generating public/private dsa key pair.

Enter file in which to save the key (/root/.ssh/id_dsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_dsa.

Your public key has been saved in /root/.ssh/id_dsa.pub.

The key fingerprint is:

fa:65:a6:b8:6f:d1:f1:e0:40:2e:56:50:85:24:99:b5 root@localhost.localdomain

The key's randomart image is:

+--[ DSA 1024]----+

|      oB+o.      |

|      o.+.       |

|       +E        |

|      o o o      |

|     . .S+ +     |

|       .. o .    |

|      .  .+      |

|       o.=       |

|      o++        |

+-----------------+

注意这里要默认敲三下回车

(2)查看产生的密钥   会产生两个文件一个id_dsa是密钥 一个id_dsa.pub是公钥

[root@localhost ~]# ls -l .ssh/

总用量 12

-rw-------. 1 root root 616 3月  28 23:12 authorized_keys

-rw-------. 1 root root 672 3月  29 02:35 id_dsa

-rw-r--r--. 1 root root 616 3月  29 02:35 id_dsa.pub

(3)把公钥发给其他服务器 要输入yes 和对向服务器的密码   这里特别注意如果对方ssh端口不是22,是其他端口用""括起来加-p

例如ssh-copy-id -i .ssh/id_dsa.pub "-p21  root@192.168.2.142"

[root@localhost ~]# ssh-copy-id -i .ssh/id_dsa.pub root@192.168.2.142

The authenticity of host '192.168.2.142 (192.168.2.142)' can't be established.

RSA key fingerprint is 1c:f0:dd:01:d6:58:5e:e9:07:37:b4:cc:c4:91:59:de.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.2.142' (RSA) to the list of known hosts.

root@192.168.2.142's password:

Now try logging into the machine, with "ssh 'root@192.168.2.142'", and check in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

(4)无密钥登录

[root@localhost ~]# ssh -p22 root@192.168.2.142

Last login: Sun May  6 20:15:39 2018 from 192.168.2.149

[root@localhost ~]# ip a | grep 192.168

inet 192.168.2.142/24 brd 192.168.2.255 scope global dynamic ens33

inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0

(5)传文件给客户端服务器 142   scp -p22端口 -rp r是目录 p是不改变文件属性 bao目录名字 root用户@ip : /root 存放的路径

[root@localhost ~]#  scp -p22 -rp bao/ root@192.168.2.142:/root

apache-tomcat-9.0.5.tar.gz                         100% 9254KB   9.0MB/s   00:00

grafana-3.1.1-1470047149.x86_64.rpm                100%   39MB  38.7MB/s   00:01

sunlogin_remoteclient_2.2.0.39537Beta.tar.gz       100% 2849KB   2.8MB/s   00:00

zabbix-3.4.7.tar.gz                                100%   16MB  16.4MB/s   00:00

nginx-1.13.9.tar.gz                                100%  971KB 971.5KB/s   00:00

jdk-8u162-linux-x64.tar.gz                         100%  181MB  45.3MB/s   00:04

客户端查看

[root@localhost ~]# cd bao/

[root@localhost bao]# ls

apache-tomcat-9.0.5.tar.gz           nginx-1.13.9.tar.gz

grafana-3.1.1-1470047149.x86_64.rpm  sunlogin_remoteclient_2.2.0.39537Beta.tar.gz

jdk-8u162-linux-x64.tar.gz           zabbix-3.4.7.tar.gz

(6)写到脚本里

给192.168.2.151服务传入公钥

vi ssh.sh

第一种方法

scp -p22 -rp bao/ root@192.168.2.142:/root

scp -p22 -rp bao/ root@192.168.2.151:/root

第二种方法

for n in 142 151

do

scp -p22 -rp bao/ root@192.168.2.$n:/root

done

sh ssh.sh

[root@localhost ~]# sh ssh.sh

apache-tomcat-9.0.5.tar.gz                                                                         100% 9254KB   9.0MB/s   00:00

grafana-3.1.1-1470047149.x86_64.rpm                                                                100%   39MB  38.7MB/s   00:00

sunlogin_remoteclient_2.2.0.39537Beta.tar.gz                                                       100% 2849KB   2.8MB/s   00:00

zabbix-3.4.7.tar.gz                                                                                100%   16MB  16.4MB/s   00:00

nginx-1.13.9.tar.gz                                                                                100%  971KB 971.5KB/s   00:00

jdk-8u162-linux-x64.tar.gz                                                                         100%  181MB  90.5MB/s   00:02

apache-tomcat-9.0.5.tar.gz                                                                         100% 9254KB   9.0MB/s   00:00

grafana-3.1.1-1470047149.x86_64.rpm                                                                100%   39MB  38.7MB/s   00:01

sunlogin_remoteclient_2.2.0.39537Beta.tar.gz                                                       100% 2849KB   2.8MB/s   00:00

zabbix-3.4.7.tar.gz                                                                                100%   16MB  16.4MB/s   00:00

nginx-1.13.9.tar.gz                                                                                100%  971KB 971.5KB/s   00:00

jdk-8u162-linux-x64.tar.gz                                                                         100%  181MB  60.3MB/s   00:03

ssh 无秘钥登录的更多相关文章

  1. ssh无秘钥登录

    服务器1:172.16.20.136 服务器2:172.16.20.134 在服务器2上输入:ssh-keygen -t rsa           (一路回车) scp /root/.ssh/id_ ...

  2. 配置SSH无秘钥登录

    [hadoop@hadoop01 ~]$ cd .ssh [hadoop@hadoop01 .ssh]$ ls authorized_keys id_rsa id_rsa.pub known_host ...

  3. Linux SSH 免秘钥登录

    SSH 免秘钥登录 ssh:是一种安全加密协议 ssh  username@hostname     ssh gongziyuan.com:以当前用户登录该机器(如果不是当前用户,需要这么干:ssh ...

  4. ansible-playbook 打通ssh无秘钥

    建议参考: http://www.cnblogs.com/jackchen001/p/6514018.html 这个代码清晰,效果佳! 参考链接: http://www.cnblogs.com/cao ...

  5. linux下ssh免秘钥登录

    1.检查防火墙是否关闭 (1)切换到root用户 (2)查看防火墙状态 service iptables status 这是没有关闭 (3)设置关闭 service iptables stop 2.检 ...

  6. SSH设置秘钥登录

    设置 SSH 通过密钥登录 我们一般使用 PuTTY 等 SSH 客户端来远程管理 Linux 服务器.但是,一般的密码方式登录,容易有密码被暴力破解的问题.所以,一般我们会将 SSH 的端口设置为默 ...

  7. 配置SSH使用秘钥登录

    使用密码远程登录ssh还是有比较大的风险的,比较安全的方法是使用秘钥登录 配置步骤如下 首先生成秘钥 ssh-keygen  (直接默认回车也可以,生成的秘钥和公钥默认防止在/root/.ssh/文件 ...

  8. ssh免秘钥登录

    简介 SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group)所制定:SSH 为建立在应用层基础上的安全协议.SSH 是目前较可靠,专为远程 ...

  9. Hadoop.2.x_无秘钥设置

    1.在实际生产环境中为Hadoop配置无秘钥登录非常有必要 # 在没有配置时: [liuwl@linux-66-64 hadoop-2.5.0]$ jps 26163 Jps [liuwl@linux ...

随机推荐

  1. learning makefile ?=

  2. UML之领域建模

    一 定义:领域建模是对领域内的概念类或现实世界中对象的可视化表示.又称概念模型.领域对象模型.分析对象模型.它专注于分析问题领域本身,发掘重要的业务领域概念,并建立业务领域概念之间的关系.业务对象模型 ...

  3. [Leetcode 217&219]寻找数组中的重复值Contains Duplicate I & II

    [题目1] Given an array of integers, find if the array contains any duplicates. Your function should re ...

  4. 26. Remove Duplicates from Sorted Array★

    题目内容: Given a sorted array, remove the duplicates in place such that each element appear only once a ...

  5. Django框架教程之正则表达式URL误区详解

    问题:我学习的视频大概是2015年录的,里面用的Django版本比较老关于正则表达式URL这一块都是用的url(“url(r'^admin/', admin.site.urls),”)方法.而我自己练 ...

  6. Android N 的开机启动流程概述

    原地址:https://blog.csdn.net/h655370/article/details/77727554 图片展示了Android的五层架构,从上到下依次是:应用层,应用框架层,库层,运行 ...

  7. IIS7.5修改asp的文件上传限制方法

    第一.IIS7.5修改asp的文件上传限制方法 1.打开IIS 2.打开面板中的应用程序开发 asp 3.找到最后的限制属性 4.修改其中的最大请求实体主体限制的值:默认为200000字节,等于195 ...

  8. python学习之闭包

    闭包:是由函数及其相关应用环境组合而成的实体(函数+引用环境) 在嵌套函数中中,如果一个内部函数对外部函数(非全局作用域)中的变量进行引用,内部函数被认为是闭包 闭包中不能修改外部环境的变量中的值 d ...

  9. SharePoint Framework解决方案管理参考(一)

    博客地址:http://blog.csdn.net/FoxDave 使用SPFx,你的企业可以轻松构建解决方案跟Office 365和SharePoint Online集成.SPFx解决方案基于现代w ...

  10. java web的MVC框架,el表达式,servlet,jstl表达式

    MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一种业务逻辑.数据.界面显示分离的方法组织代码 ...