Git升级至2.39后执行mvn release:prepare遇SSH权限拒绝问题
Maven Release:Prepare 执行时Git SSH权限错误问题
在Windows 10的Git Bash控制台执行mvn release:prepare命令时,出现如下权限错误:
[ERROR] Permission denied, please try again. [ERROR] git@gitlab.XXX.fr: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). [ERROR] fatal: Could not read from remote repository. [ERROR] [ERROR] Please make sure you have the correct access rights [ERROR] and the repository exists.
异常情况说明:同一控制台执行git push命令完全正常,说明当前环境的SSH密钥配置有效,但Maven Release插件无法正确使用该密钥。此问题是在将Git升级至2.39版本后出现的,此前功能运行正常。
项目pom.xml相关配置
build及scm部分内容如下:
<build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-toolchains-plugin</artifactId> <version>1.1</version> <executions> <execution> <goals> <goal>toolchain</goal> </goals> </execution> </executions> <configuration> <toolchains> <jdk> <version>${maven.compiler.source}</version> </jdk> </toolchains> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.1.0</version> <configuration> <dependentWarExcludes>WEB-INF/lib/*</dependentWarExcludes> <webResources> <resource> <directory>src/main/webapp</directory> <!-- enable filtering --> <filtering>true</filtering> <includes> <include>META-INF/context.xml</include> </includes> </resource> <resource> <directory>src/main/webapp</directory> <!-- enable filtering --> <filtering>false</filtering> <excludes> <exclude>META-INF/context.xml</exclude> </excludes> </resource> </webResources> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <version>2.4.1</version> <configuration> <tagNameFormat>v@{project.version}</tagNameFormat> <arguments>-Dmaven.javadoc.skip=true</arguments> </configuration> <dependencies> <dependency> <groupId>org.apache.maven.shared</groupId> <artifactId>maven-invoker</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-scm-plugin</artifactId> <version>1.8.1</version> </dependency> </dependencies> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>2.6</version> </plugin> </plugins> </build> <scm> <developerConnection>scm:git:ssh://git@gitlab.XXX.fr/YYY.git</developerConnection> <url>https://gitlab.XXX.fr/YYY</url> <tag>v5.1.31</tag> </scm>
解决方法
1. 升级Maven SCM插件版本
当前使用的maven-scm-plugin版本为1.8.1(通过maven-release-plugin依赖引入),该版本发布于2013年,无法兼容Git 2.39版本的SSH协议变化。将其升级至最新稳定版本(如1.12.2):
修改maven-release-plugin的dependencies部分:
<dependency> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-scm-plugin</artifactId> <version>1.12.2</version> </dependency>
同时建议将maven-release-plugin也升级至较新版本(如3.0.0-M7),进一步提升兼容性。
2. 配置Git启用兼容的SSH算法(临时方案)
如果暂时无法升级插件,可通过修改SSH配置,让Git允许旧的RSA算法(Git 2.39默认禁用了SHA-1签名的RSA密钥):
在Git Bash中编辑~/.ssh/config文件(若不存在则新建),添加以下内容:
Host gitlab.XXX.fr PubkeyAcceptedAlgorithms +ssh-rsa HostKeyAlgorithms +ssh-rsa
保存后重新执行mvn release:prepare命令。
3. 验证SSH连接
在Git Bash中执行以下命令,确认密钥可正常访问GitLab:
ssh -T git@gitlab.XXX.fr
若返回欢迎信息,说明密钥配置正常,问题集中在Maven插件的兼容性上。
内容的提问来源于stack exchange,提问作者Clément Picou
相关产品推荐
相关产品推荐

