Windows环境Jenkins配置免密登录Linux

Windows免密登录可以提供很多便利,如Jenkins连接Linux等,批量启动集群等

1.首先,Windows机器安装ssh组件:

官网 https://www.mls-software.com/opensshd.html 下载,一路安装就行

安装可参考 https://blog.csdn.net/wm609972715/article/details/83759114

2.Windows机器cmd执行 ssh-keygen -t rsa -C "name@163.com"

邮箱替换为自己的邮箱

会提示公私钥生成到哪个文件夹

3.进入文件夹,把公钥拷到Linux服务器,用 rz 命令上传

4.连接Linux机器,把公钥追加到 authorized_keys 文件末尾,具体操作如下:

进入目录: cd  /root/.ssh

追加文本: cat  id_rsa.pub >> authorized_keys

(注:cat打开文件,>>输出重定向,>是覆盖文件,>>是追加到末尾)

5.在Windows机器测试连接:

cmd执行: ssh -p22 root@{Linux机器ip}

6.如果出现权限错误,Permission are too open,那么在Windows机器删除所有权限即可,具体操作:

右击 id_rsa 文件,选择安全,把其他用户的权限全部删除,保留如下图就可以

这只是刚刚开始,下面我们在Jenkins构建 Execute Windows batch command:

set remote_user=root
set remote_ip=10.138.60.76
set remote_path="/home/REQ501"
set backup_path=%remote_path:~0,-1%/backup"

ssh %remote_user%@%remote_ip% "ps -ef | grep %jar_file% | grep -v grep | cut -c 9-15"

直接执行,报错:Could not create directory '/home/SYSTEM/.ssh'

这时候你需要再openssh安装目录下新建/home/SYSTEM,然后把.ssh文件夹拷过来

 此步参考:https://www.douban.com/note/574926633/

PS:

其他问题可参考:https://www.jianshu.com/p/ebcf41c75786

参考文档:https://blog.csdn.net/qq_38366063/article/details/98340100?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

原文地址:https://www.cnblogs.com/carlvine/p/12625003.html