微网站免费平台,做网站为什么要用源码,wordpress主题兼容,网站有关于我们的好处一、背景
使用jenkins的ssh插件传输文件至远程机器的指定目录#xff0c;php程序打包后#xff0c;经过zip压缩为oms.zip
zip -rq oms.zip ./ -x .git/* -x .env然后我们求md5值
md5sum oms.zip最后执行传输。
09:03:02 Executing command on ssh[116.61.10.149]: mkdir…一、背景
使用jenkins的ssh插件传输文件至远程机器的指定目录php程序打包后经过zip压缩为oms.zip
zip -rq oms.zip ./ -x .git/* -x .env然后我们求md5值
md5sum oms.zip最后执行传输。
09:03:02 Executing command on ssh[116.61.10.149]: mkdir -p /opt/php/oms sudo: false
[Pipeline] sshPut
[Pipeline] }
09:03:07 Sending a file/directory to ssh[116.61.10.149]: from: /home/jenkins/agent/workspace/PROD_resource_php_oms/oms.zip into: /opt/php/oms
09:03:08 Failed SFTP PUT: /home/jenkins/agent/workspace/PROD_resource_php_oms/oms.zip - ssh:/opt/php/oms二、报错详情 Caused: org.hidetake.groovy.ssh.operation.SftpException: Failed SFTP PUT: /home/jenkins/agent/workspace/PROD_resource_php_oms/oms.zip - ssh:/opt/php/oms: (SSH_FX_PERMISSION_DENIED: The user does not have sufficient permissions to perform the operation): Permission denied 三、ssh pipeline def remote [:]remote.name sshremote.host 116.61.10.149remote.port 22remote.allowAnyHosts truedef credentialsId 285a0928-f35f-4485-a54f-48321aea7212withCredentials([sshUserPrivateKey(credentialsId: credentialsId, keyFileVariable: identity, passphraseVariable: )]) {remote.user phpuserremote.identityFile identity// 创建远程目录sshCommand remote: remote, command: mkdir -p remoteFilePath// 上传jar或者zip包以及md5文件sshPut remote: remote, from: jarFileName, into: remoteFilePathsshPut remote: remote, from: md5FileName, into: remoteFilePath// 如果是zip压缩文件额外上传一个.version文件内容是版本号if (.zip fileType) {sshPut remote: remote, from: .version, into: remoteFilePath}}
四、排查过程
手动登录远程机器116.61.10.149然后进入目标目录查看目录所属的用户是root而非phpuser所以报没有权限的错误。
[rootTEST-jekines ~]# ssh phpuser116.61.10.149
Last login: Thu Jul 28 09:52:44 2022 from 116.61.10.149Welcome to Alibaba Cloud Elastic Compute Service ![phpuserawx-pre ~]$ cd /opt/php
[phpuserawx-pre php]$ ll
total 15
drwxr-xr-x 2 root root 4096 Jul 25 09:51 oms查看文件夹的详情
[phpuserawx-pre php]$ stat omsFile: ‘oms’Size: 4096 Blocks: 1 IO Block: 16384 directory
Device: 56h/86d Inode: 6993897 Links: 2
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2023-07-25 09:51:29.613946996 0800
Modify: 2023-07-25 09:51:29.613946996 0800
Change: 2023-07-25 09:51:29.613946996 0800Birth: -文件夹oms是在2023-07-25 09:51:29由用户root创建的所以当phpuser用户来尝试创建目录的时候会失败继而传输文件也报权限非法的错误。
五、解决问题
rm -rf /opt/php删除后目录/opt/php下为空 重试上传文件
[phpuserawx-pre oms]$ ll -h
total 170M
-rw-rw-r-- 1 phpuser phpuser 170M Jul 31 10:06 oms.zip
-rw-rw-r-- 1 phpuser phpuser 33 Jul 31 10:06 oms.zip.md5