场景:

jenkins 需要自动登陆到远程服务器

1. 生成 ssh 公钥和私钥(在 jenkins 服务器上执行)

xiluhua@vm-xiluhua ~ $ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/xiluhua/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/xiluhua/.ssh/id_rsa.
Your public key has been saved in /home/xiluhua/.ssh/id_rsa.pub.
The key fingerprint is:
4f::::ac:5d::ed:b2::de:8d:9f:eb:: xiluhua@vm-xiluhua
The key's randomart image is:
+--[ RSA ]----+
| ..oo.. |
| oo.o .|
| o.o . |
| .o. . .|
| S o o o |
| o o . |
| .. . o |
| . oE=|
| .**|
+-----------------+

2. 查看生成结果

xiluhua@vm-xiluhua ~ $ cd /home/xiluhua/.ssh/
xiluhua@vm-xiluhua ~/.ssh $ ll
总用量
-rw-------. xiluhua xiluhua // :: id_rsa
-rw-r--r--. xiluhua xiluhua // :: id_rsa.pub
-rw-r--r--. xiluhua xiluhua // :: known_hosts

3. 将公钥部署到目标客户端(一)

xiluhua@vm-xiluhua ~/.ssh $ ssh-copy-id -i id_rsa.pub loginuser@10.1.118.45
/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: key(s) remain to be installed -- if you are prompted now it is to install the new keys
xiluhua@192.168.178.132's password: Number of key(s) added: Now try logging into the machine, with: "ssh 'loginuser@10.1.118.45'"
and check to make sure that only the key(s) you wanted were added.

3. 将公钥部署到目标客户端(二)

scp -p ~/.ssh/id_rsa.pub loginuser@10.1.118.45:/home/weblogic/.ssh/authorized_keys

实在不行,手动复制到目标机器上也可以

4. 验证

xiluhua@vm-xiluhua ~/.ssh $ ssh loginuser@10.1.118.45
Last login: Tue Jul 25 21:27:55 2017 from 192.168.178.1
******************************
*** welcome! xiluhua ***
******************************
xiluhua@localhost ~ $

return "SUCCESS";

最新文章

  1. Sql Server 数据分页
  2. 省市区县镇级联数据JS版
  3. yarn的调度策略
  4. 用Time Machine做更换电脑工具
  5. JqueryPagination 分页插件使用说明
  6. OC4_单例
  7. 【转】MFC下拉列表框的用法
  8. 02函数-04-箭头函数(ES6)
  9. Apache配置腾讯云SSL证书指引
  10. JQuery设置checkbox的值,取checkbox的值,设置radio的值,取radio的值,设置下拉选select的值,取select的值
  11. python 基础之变量存储缓存机制与数据驻留小数据池
  12. Vue 组件&组件之间的通信 之全局组件与局部组件
  13. lambda函数的特性
  14. eclipse 把鼠标指针放在错误的语句上 提示快速修正 不见了的解决方法
  15. ElasticSearch相关文章推荐
  16. Cookies与session的区别
  17. SSH无密码登录:只需两个简单步骤 (Linux)
  18. 大文件上传插件webupload插件
  19. codevs 1079 回家
  20. 将War发布到Tomcat7上遇到的问题及其解决

热门文章

  1. JavaScript, DOM查找元素
  2. es分词器
  3. what's the 数据结构
  4. Python字符串切片
  5. 帝国cms-tab
  6. 清空select标签中option选项的3种不同方式
  7. sap QG3搜索
  8. 如何在CentOS 7中安装最新Git(源码安装)
  9. matplot绘图
  10. android studio 设置安装不占用C盘