[持续集成] ansible 免密登陆

2019-02-14  本文已影响0人  w_w_wei

生成秘钥,将公钥通过ssh-copy-id

ssh-keygen -t rsa   
ssh-copy-id -i /var/jenkins_home/.ssh/id_rsa.pub -p 20022 admin@192.168.3.15

输出如下

jenkins@b5dda696b2ee:/$ ssh-keygen -t rsa                                                                                                                                                                    
Generating public/private rsa key pair.                                                                                                                                                                      
Enter file in which to save the key (/var/jenkins_home/.ssh/id_rsa):                                                                                                                                         
Enter passphrase (empty for no passphrase):                                                                                                                                                                  
Enter same passphrase again:                                                                                                                                                                                 
Your identification has been saved in /var/jenkins_home/.ssh/id_rsa.                                                                                                                                         
Your public key has been saved in /var/jenkins_home/.ssh/id_rsa.pub.                                                                                                                                         
The key fingerprint is:                                                                                                                                                                                      
SHA256:ihdBNOQXkgYjvucifgVSUjSM7e7u0XpcRrS75UItWWY jenkins@b5dda696b2ee                                                                                                                                      
The key's randomart image is:                                                                                                                                                                                
+---[RSA 2048]----+                                                                                                                                                                                          
|  B+o+*..        |                                                                                                                                                                                          
| + =.+o+ .       |                                                                                                                                                                                          
|  =  .+ o        |                                                                                                                                                                                          
| . +   = E       |                                                                                                                                                                                          
|  + o o S        |                                                                                                                                                                                          
jenkins@b5dda696b2ee:/$ cd ~                                                                                                                                                                                 
jenkins@b5dda696b2ee:~$ ls .ssh                                                                                                                                                                              
id_rsa  id_rsa.pub  known_hosts                                                                                                                                                                              
jenkins@b5dda696b2ee:~$ ssh-copy-id -i /var/jenkins_home/.ssh/id_rsa.pub -p 20022 admin@192.168.3.15                                                                                                         
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/var/jenkins_home/.ssh/id_rsa.pub"                                                                                                            
/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                                                                                         
admin@192.168.3.15's password:                                                                                                                                                                               
                                                                                                                                                                                                             
Number of key(s) added: 1                                                                                                                                                                                    
                                                                                                                                                                                                             
Now try logging into the machine, with:   "ssh -p '20022' 'admin@192.168.3.15'"                                                                                                                              
and check to make sure that only the key(s) you wanted were added.
上一篇 下一篇

猜你喜欢

热点阅读