ssh 秘钥认证流程

ssh配置认证

基于口令(密码)的安全验证

[root@m01 ~]# ssh 10.0.0.41 hostname
root@10.0.0.41's password:
backup
[root@m01 ~]# ssh 10.0.0.41 whoami
root@10.0.0.41's password:
root
[root@m01 ~]# ssh lewen@10.0.0.41 whoami
lewen@10.0.0.41's password:
lewen

基于秘钥的认证

1.生成钥匙和锁头

[root@m01 ~]# hostname
m01
[root@m01 ~]# 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:
::1b:e1:9f:0a:ab::a0:fc:::2d:bc::dd root@m01
The key's randomart image is:
+--[ DSA ]----+
| |
| . + . |
| = + E |
| . + . o |
| o . S |
| ..o = . |
| .o.... o |
| .o..o.. |
| .+o.. |
+-----------------+

2.把锁头发送到目标机器

发送到 backup
[root@m01 ~]# ssh-copy-id -i /root/.ssh/id_dsa.pub root@172.16.1.41
The authenticity of host '172.16.1.41 (172.16.1.41)' can't be established.
RSA key fingerprint is ac:0f:aa:d2:5b:ff:cf:ac:f0:::a6:be::b9:f9.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added '172.16.1.41' (RSA) to the list of known hosts.
root@172.16.1.41's password:
Now try logging into the machine, with "ssh 'root@172.16.1.41'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
[root@m01 ~]# ssh 10.0.0.41 hostname
backup


#nfs01
[root@m01 ~]# ssh-copy-id -i /root/.ssh/id_dsa.pub root@172.16.1.31
The authenticity of host '172.16.1.31 (172.16.1.31)' can't be established.
RSA key fingerprint is ac:0f:aa:d2:5b:ff:cf:ac:f0:::a6:be::b9:f9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.1.31' (RSA) to the list of known hosts.
root@172.16.1.31's password:
Now try logging into the machine, with "ssh 'root@172.16.1.31'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
[root@m01 ~]# ssh 172.16.1.31 hostname
nfs01

3.免密发送

sshpass 软件
yum install sshpass -y #sshpass 给ssh类提供密码
[root@m01 ~]# sshpass -p123456 ssh 172.16.1.41 hostname
backup
sshpass -p123456 ssh -o StrictHostKeyChecking=no 172.16.1.41 hostname
backup

非交互式创建 钥匙锁头

[root@m01 ~]# ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa

非交互式 分发公钥

不用输入密码将公钥发送到目的机器

[root@m01 ~]# sshpass -p123456 ssh-copy-id -i /root/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no root@172.16.1.41"
Now try logging into the machine, with "ssh '-o StrictHostKeyChecking=no root@172.16.1.41'",
and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.


[root@m01 ~]# sshpass -p123456 ssh-copy-id -i /root/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no root@172.16.1.31"
Now try logging into the machine, with "ssh '-o StrictHostKeyChecking=no root@172.16.1.31'",
and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
​ [root@m01 ~]# ssh 172.16.1.41 hostname
backup
[root@m01 ~]# ssh 172.16.1.31 hostname
nfs01
Usage: /usr/bin/ssh-copy-id [-h|-?|-f|-n] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname
-f: force mode -- copy keys without trying to check if they are already installed
-n: dry run -- no keys are actually copied

ssh 认证的更多相关文章

  1. ssh 认证指定端口

    [root@database2 ~]# cat ssh.sh if [ ! $# -eq 2 ] ;then echo "请输入用户密码以空格分开" exit else ssh-k ...

  2. 批量的单向的ssh 认证

    <pre name="code" class="python">if [ ! $# -eq 2 ] ;then echo "请输入用户密码 ...

  3. debian下使用gitosis+gitweb搭建SSH认证的git服务器

    搭建完成Git服务器后,需要使用两台机器进行测试,一台机器作为服务器端server,一台服务器作为客户端client.整个系统,需要三个计算机账户,这里假设server端的账户名为git,client ...

  4. github添加ssh认证

    总概:在使用git的时候,和目标仓库建立关系有两种方式https,ssh.一般用的是https认证(这样简单方便),但有个缺点,pull,push等操作需要频繁输入用户验证.虽然可以把用户验证账号密码 ...

  5. Linux学习笔记总结--ssh认证登录

    原理简介 SSH证书认证登录的基础是一对唯一匹配密钥: 私钥(private key)和公钥(public key).公钥用于对数据进行加密,而且只能用于加密.而私钥只能对使用所匹配的公钥,所加密过的 ...

  6. git ssh认证

    一般新手用git时,使用HTTPS都需要输入用户名和密码,这是一个很低效的开发过程.(虽然有时可以让开发人员减少push的次数).github提供了几种连接方式,其中以https:开头的代表https ...

  7. 华为SSH认证配置

    [设备型号]华为switch-S5700s ————1: [SW1] rsa/dsa local-key-pair create #创建本地密钥对 The key name will be: SW1_ ...

  8. Jenkins - SSH认证方式拉取Git代码

    1.本地生成密钥 [root@root ~] ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which ...

  9. [Linux] 一次SSH认证失败引发的关于通过日志查错误的思考

    一.缘由: 早上在用SSH公钥认证打通所有的机器,有一台机器在完成一些列操作后密钥登陆失败,其他机器一切正常. 错误如下:Public-key authentication with the serv ...

随机推荐

  1. Java 微服务框架选型 Dubbo 和 Spring Cloud

    微服务(Microservices)是一种架构风格,一个大型复杂软件应用由一个或多个微服务组成.系统中的各个微服务可被独立部署,各个微服务之间是松耦合的.每个微服务仅关注于完成一件任务并很好地完成该任 ...

  2. jQuery和js使用点滴

    1.checkbox全选按钮 <input type="checkbox" name="allcheck" id="allcheck" ...

  3. Java_反射_范型

    虽然从来没有被面过,但是必须知道,因为classForname classloader被面过多次了. 一.Class.forName动态加载  1.编译时加载类是静态加载类,             ...

  4. 使用go语言的list实现一个简单的LRU缓存

    package main; import ( "container/list" "errors" "sync" "fmt" ...

  5. SQL truncate 、delete与drop区别[z]

    [z]https://www.cnblogs.com/8765h/archive/2011/11/25/2374167.html 相同点: 1.truncate和不带where子句的delete.以及 ...

  6. Ubuntu安装时没注册root用户密码,怎么登录root

    一.其实我个人认为这没有多大必要,因为当你需要 root 的权限时,使用 sudo 便可以了.如果你实在需要在 Ubuntu 中启用 root 帐号的话,那么不妨执行下面的操作: 1.重新设置 roo ...

  7. centos7+nginx+rtmp+ffmpeg搭建流媒体服务器

    1.安装前需要的工具 #net-tool 查本地IP #wget 下载安装包 #unzip 解压zip包 #gcc gcc-c++ perl 编译软件包用 yum install -y net-too ...

  8. JAVA动手动脑及课后作业

    1.查看其输出结果.如何解释这样的输出结果?从中你能总结出什么? 运行结果 true true false 原因 1)在Java中,内容相同的字串常量(“Hello”)只保存一份以节约内存,所以s0, ...

  9. python自学开始

    95年工科女一枚 java工程师算不上,只能说从事java开发相关的工作,由于对Python有着极其浓厚的兴趣,一周时间了解大概之后,决定从今天开始见缝插针自学Python,为了防止本人三天打鱼两天晒 ...

  10. Taxi

    /* After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to cele ...