リモート接続を検証するためのLinuxサーバー、クライアント間でキーの構築

リモート接続を検証するためのLinuxサーバー、クライアント間でキーの構築
クライアント:192.168.1.10 zhangsanユーザーの
サーバー:ユーザーが192.168.1.20リージ
クライアントで鍵ペアを作成します。

[zhangsan@localhost /]$ ssh-keygen -t ecdsa         # -t 用来指定算法类型:ecdsa和dsa
Generating public/private ecdsa key pair.
Enter file in which to save the key (/home/zhangsan/.ssh/id_ecdsa):     # 指定私钥位置
Created directory '/home/zhangsan/.ssh'.
Enter passphrase (empty for no passphrase):             # 设置私钥短语
Enter same passphrase again:                            # 确认所设置的私钥短语
Your identification has been saved in /home/zhangsan/.ssh/id_ecdsa.
Your public key has been saved in /home/zhangsan/.ssh/id_ecdsa.pub.
The key fingerprint is:
81:3b:35:3b:8f:12:60:ba:f5:68:57:b0:ae:35:2c:fe [email protected]
The key's randomart image is:
+--[ECDSA  256]---+
|                 |
|       .         |
|    o o +        |
|   o . = +       |
|  . . = S        |                                      # 一般出来左边这一串就说明对了
|   o = + +       |
|  . + O . .      |
|   o = o         |
|    o.E          |
+-----------------+

秘密鍵ファイルを保護するために使用される秘密キーフレーズは、リモート接続時に正しい秘密キーフレーズを入力する必要があります。プライベートキーフレーズが設定された場合は、無料のパスワードログインを達成するために、それを接続したとき、そして、これは推奨されません。
一般を通じてクライアント鍵ペア、サーバにアップロード公開鍵、公開鍵のテキスト内のサーバ、キー認証クライアント作成する
第二ステップと、別の方法の第3工程を達成するために使用することができます:

[zhangsan@localhost /]$ ssh-copy-id -i ~/.ssh/id_ecdsa.pub [email protected] -p 2345                         # -i 选项用来指定公钥文件
The authenticity of host '[192.168.1.20]:2345 ([192.168.1.20]:2345)' can't be established.
ECDSA key fingerprint is 68:df:0f:ac:c7:75:df:02:88:7d:36:6a:1a:ae:27:23.
Are you sure you want to continue connecting (yes/no)? 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
[email protected]'s password:           # lisi 用户的密码    验证后会将公钥添加到lisi宿主目录下的./sshauthorized_keys 文件

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh -p '2345' '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

確認するために、キーを使用します。

[zhangsan@localhost /]$ ssh -p 2345 [email protected]
Enter passphrase for key '/home/zhangsan/.ssh/id_ecdsa':        # 这里输入私钥短语,就不需要输入lisi的密码了
Last login: Fri Aug 16 18:19:48 2019 from 192.168.1.10
[lisi@mysql ~]$ 

おすすめ

転載: blog.51cto.com/14227204/2430558