当前位置:网站首页>通过Jenkins 拉取服务器代码 权限不足问题及其他注意事项
通过Jenkins 拉取服务器代码 权限不足问题及其他注意事项
2022-07-28 11:40:00 【yi_tianchou】
在网络浏览到一个问题:
我用一个commanline在linux下生成了public/private ssh key, 用git clone 没有问题,但是在jenkins 上创建了job,运行就是连不上,有人知道怎么回事吗?
Failed to connect to repository : Command "git ls-remote -h XXXHEAD" returned status code 128:
stdout:
stderr: Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-with-mic,password).
fatal: Could not read from remote repository.
刚好前几天解决了这个问题,也是想记录一下,一直没空出时间.
今天记录一下,毕竟当时也是从网上找了好几天的答案都没找到.
上述问题原因, linux下 可以git 到服务器代码,是因为自己电脑上通过 ssh -keygen -t -rsa "用户信息" 将公私钥添加到了本地,同时将公钥添加到了服务器,
如果这些步骤没做,也不可能 Command 下拉到代码.
Command 可以拉取代码 ,而jenkins不行 这里关乎一个很重要也很诡异的文件 known_hosts
1、known_hosts简介
ssh会把你每个你访问过计算机的公钥(public key)都记录在~/.ssh/known_hosts。当下次访问相同计算机时,OpenSSH会核对公钥。如果公钥不同,OpenSSH会发出警告, 避免你受到DNS Hijack之类的攻击
具体的 SSH 原理(免密登录)可以参考 :https://www.cnblogs.com/zqj-blog/p/10445598.html
2、known_hosts问题分析
本地访问服务的时候 会在 .ssh下生成 known_hosts,而jenkins 是运行在 Tomcat下的, Tomcat无法访问到你本地的 known_hosts,且原理上 known_hosts 删除之后可以自动生成,但是 tomcat下 首先连接不成功不会创建,其次删除之后不会自动生成.
解决办法: 把本地的 .ssh下的 known_hosts 拷贝到 Tomcat下(具体路径要自己看)
3、其他可能存在的问题
1) 账号问题 ,jenkins 运行在tomcat下,其实连接jenkins上执行的 git其实使用的是 Tomcat账号,而不是 登录的用户,这点要注意,所以任何和git相关的 都要给tomcat配置权限,否则一样产生权限问题
2)路径问题,
git使用的公私钥对 ,同时要拷贝一份到tomcat下,包括刚才提到的 known_hosts ,因为tomcat没有能力访问 tomcat以为的文件
时间仓促,写的比较粗,侵删,错改.多多包涵
边栏推荐
猜你喜欢

The usage and Simulation Implementation of vector in STL

Is it overtime to be on duty? Take up legal weapons to protect your legitimate rights and interests. It's time to rectify the working environment

新零售电商O2O模式解析

Why do enterprises need the ability of enterprise knowledge management?

顶级“Redis笔记”,缓存雪崩+击穿+穿透+集群+分布式锁,NB了

华为发布HarmonyOS 3及全场景新品,智慧体验更进一步

Basic use of JSON server

sqli-labs(less-8)

要想组建敏捷团队,这些方法不可少

30 years of open source community | 2022 open atom global open source summit 30 years of special activities of open source community were successfully held
随机推荐
Basic use of JSON server
AsiaInfo technology released antdb7.0, a "Telecom grade" core transaction database, to help government and enterprises "trust" to create the future!
[Nuxt 3] (十二) 项目目录结构 3
新零售电商O2O模式解析
Developing NES games with C language (cc65) 10. Game cycle
【萌新解题】爬楼梯
图书馆自动预约脚本
Unity加载Glb模型
Redis实现分布式锁
用C语言开发NES游戏(CC65)11、Metatiles
Industry, University, research and application jointly build an open source talent ecosystem | the 2022 open atom global open source summit education sub forum was successfully held
用C语言开发NES游戏(CC65)04、完整的背景
【Base】优化性能到底在优化啥?
Minimally invasive electrophysiology has passed the registration: a listed enterprise with annual revenue of 190million minimally invasive mass production
SQL injection LESS18 (header injection + error injection)
金九银十 再不卷就来不及了
【vulnhub】Raven2
用C语言开发NES游戏(CC65)06、精灵
1331. 数组序号转换 : 简单模拟题
Some API interfaces purchased by Yiwu hope to bring you some help