ssh passphrase 测试

前提

本文用于针对云平台下的 VM 中的 vclound 用户利用 ssh 密钥登录进行的测试

测试目标

vclound 用户需要利用 ssh key 进行登录
ssh key 验证时需要输入 passphrase 进行校验
在脚本中需要对多台电脑进行 vclound 用户登录测试时候,   进行 key 校验过程中, 只需要输入一次 passphrase 即可同时以 vclound 用户登录多台电脑

测试机器

ip addressrole
192.168.209.100controll server
192.168.209.101ssh 测试对象
192.168.209.102ssh 测试对象
192.168.209.103ssh 测试对象
192.168.209.104ssh 测试对象

创建用户

useradd vclound

为 vclound 用户创建 passphrase

[vclound@gz-controller-209100 ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/vclound/.ssh/id_rsa):
Created directory '/home/vclound/.ssh'.
Enter passphrase (empty for no passphrase):   <- 输入 passphrase
Enter same passphrase again:                  <- 重复输入 passphrase
Your identification has been saved in /home/vclound/.ssh/id_rsa.
Your public key has been saved in /home/vclound/.ssh/id_rsa.pub.
The key fingerprint is:
f4:d6:d0:03:c6:7c:b8:e8:54:80:57:d8:8f:1d:ce:68 vclound@gz-controller-209100.vclound.com
The key's randomart image is:
+--[ RSA 2048]----+
|       ..B+.     |
|      . o.*oo    |
|       ..o.Xo.   |
|       .o.Eo=.   |
|       oS.o .    |
|        ..       |
|                 |
|                 |
|                 |
+-----------------+

为 ssh 测试对象创建 vclound 用户

[root@gz-controller-209100 ~]# ssh 192.168.209.101 useradd vclound
[root@gz-controller-209100 ~]# ssh 192.168.209.102 useradd vclound
[root@gz-controller-209100 ~]# ssh 192.168.209.103 useradd vclound
[root@gz-controller-209100 ~]# ssh 192.168.209.104 useradd vclound

传输 ssh key 到 ssh 测试对象

[root@gz-controller-209100 ~]# ssh 192.168.209.101 mkdir /home/vclound/.ssh/
[root@gz-controller-209100 ~]# ssh 192.168.209.102 mkdir /home/vclound/.ssh/
[root@gz-controller-209100 ~]# ssh 192.168.209.103 mkdir /home/vclound/.ssh/
[root@gz-controller-209100 ~]# ssh 192.168.209.104 mkdir /home/vclound/.ssh/
[root@gz-controller-209100 ~]# scp /home/vclound/.ssh/id_rsa.pub  192.168.209.101:/home/vclound/.ssh/authorized_keys
id_rsa.pub                                                                                  100%  422     0.4KB/s   00:00
[root@gz-controller-209100 ~]# scp /home/vclound/.ssh/id_rsa.pub  192.168.209.102:/home/vclound/.ssh/authorized_keys
id_rsa.pub                                                                                  100%  422     0.4KB/s   00:00
[root@gz-controller-209100 ~]# scp /home/vclound/.ssh/id_rsa.pub  192.168.209.103:/home/vclound/.ssh/authorized_keys
id_rsa.pub                                                                                  100%  422     0.4KB/s   00:00
[root@gz-controller-209100 ~]# scp /home/vclound/.ssh/id_rsa.pub  192.168.209.104:/home/vclound/.ssh/authorized_keys
id_rsa.pub                                                                                  100%  422     0.4KB/s   00:00

创建脚本测试

[vclound@gz-controller-209100 ~]$ cat /home/vclound/ssh_test.sh
#!/bin/bash
# just test ssh login and show up ip address
# terry tsang

for id in 1 2 3 4
do
  ssh 192.168.209.10$id /sbin/ifconfig bond0 |  awk -F[:\ ] '/netmask/ {print $10}'
done

参见下面执行方法

注: 在执行 ssh-agent bash 后, 将会产生 bash 子进程, 并且利用 ssh-add 导入 id_rsa 后, 将需要输入 passphrase , 并把密钥信息保存到当前 bash 中, 在执行脚本后, 建议执行 exit 退出该 shell

[vclound@gz-controller-209100 ~]$ ssh-agent bash
[vclound@gz-controller-209100 ~]$ ssh-add /home/vclound/.ssh/id_rsa
Enter passphrase for /home/vclound/.ssh/id_rsa:   <- 输入 passphrase
Identity added: /home/vclound/.ssh/id_rsa (/home/vclound/.ssh/id_rsa)
[vclound@gz-controller-209100 ~]$ ./ssh_test.sh
192.168.209.101
192.168.209.102
192.168.209.103
192.168.209.104

修改 passphrase 方法

[vclound@gz-controller-209100 ~]$ ssh-keygen -p
Enter file in which the key is (/home/vclound/.ssh/id_rsa):    <- 输入私钥存放位置
Enter old passphrase:                                          <- 输入旧的 passphrase 
Key has comment '/home/vclound/.ssh/id_rsa'
Enter new passphrase (empty for no passphrase):                <- 输入新的 passphrase
Enter same passphrase again:                                   <- 重复输入新的 passphrase
Your identification has been saved with the new passphrase.

测试新 passphrase

[vclound@gz-controller-209100 ~]$ ssh-agent bash
[vclound@gz-controller-209100 ~]$  ssh-add /home/vclound/.ssh/id_rsa
Enter passphrase for /home/vclound/.ssh/id_rsa:                           <- 输入新的 passphrase 
Identity added: /home/vclound/.ssh/id_rsa (/home/vclound/.ssh/id_rsa)
[vclound@gz-controller-209100 ~]$ ./ssh_test.sh
192.168.209.101
192.168.209.102
192.168.209.103
192.168.209.104
[vclound@gz-controller-209100 ~]$ exit                                     <- 退出 ssh-agent shell
exit
[vclound@gz-controller-209100 ~]$
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值