情境
server-1 不用輸入密碼遠端登入 server-2 

1. 在sever-1 執行以下程式
[demo@server-1 ~]$ ssh-keygen
Generating public/private rsa key pair.

Enter file in which to save the key (/home/demo/.ssh/id_rsa): Created directory '/home/demo/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/demo/.ssh/id_rsa.
Your public key has been saved in /home/demo/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:NVuWJ+wjm/tsVEAOhYew*********9ycOM demo@server-1.example
The key's randomart image is:
+---[RSA 3072]----+
|        o..=o    |
|     o o oo+o.   |
|    o + * o.B..  |
|   .   O + * o.  |
|  . . o S = o.   |
|   o * . + =..   |
|  . + . o E.     |
|   +     + o.    |
|  o..     .oo    |
+----[SHA256]-----+

2. 複製金鑰到遠端sevrer 
[demo@server-1 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub demo@server-2
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/demo/.ssh/id_rsa.pub"
The authenticity of host 'server-2 (server-2)' can't be established.
ECDSA key fingerprint is SHA256:XrU/twqZ2xOUZzel******VZV2SLOtiEo.
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
demo@server-2's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'demo@server-2'"
and check to make sure that only the key(s) you wanted were added.

3. 測試是否可以登入執行程式,並且無須輸入密碼
[demo@server-1 ~]$ ssh demo@server-2 hostname
server-2

undefined

arrow
arrow
    文章標籤
    ssh without password linux
    全站熱搜

    helloworld 發表在 痞客邦 留言(0) 人氣()