linux 下git出现 Permission denied (publickey). fatal: 无法读取远程仓库。

背景: 

marhal@php-ubuntu18:/var/www/html$  composer create-project laravel/laravel Laravel-1 --prefer-dist "5.8.*"
marhal@php-ubuntu18:/var/www/html/Laravel-1$ sudo chown -R www-data:www-data bootstrap/
marhal@php-ubuntu18:/var/www/html/Laravel-1$ sudo chown -R www-data:www-data storage/
marhal@php-ubuntu18:/var/www/html/Laravel-1$ cd
marhal@php-ubuntu18:~$ git config --global user.name 'Marhal'
marhal@php-ubuntu18:~$ git config --global user.email 'xxxxxx@sina.com'
marhal@php-ubuntu18:~$ git config --global push.default simple
marhal@php-ubuntu18:~$ cd /var/www/html/Laravel-1/
marhal@php-ubuntu18:/var/www/html/Laravel-1$ git init
已初始化空的 Git 仓库于 /var/www/html/Laravel-1/.git/
marhal@php-ubuntu18:/var/www/html/Laravel-1$ git add -A
marhal@php-ubuntu18:/var/www/html/Laravel-1$ git commit -m "init projext"
marhal@php-ubuntu18:/var/www/html/Laravel-1$ git remote add origin git@code.aliyun.com:Marhal/Laravel-1.git
marhal@php-ubuntu18:/var/www/html/Laravel-1$ git push -u origin master
The authenticity of host 'code.aliyun.com (120.55.150.20)' can't be established.
RSA key fingerprint is SHA256:ZrA2ZqYTVyPbw4zytCSAv74ZMaS2LDH74I7sMPtQIG0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'code.aliyun.com,120.55.150.20' (RSA) to the list of known hosts.
git@code.aliyun.com: Permission denied (publickey).
fatal: 无法读取远程仓库。

请确认您有正确的访问权限并且仓库存在。

解决方案:

marhal@php-ubuntu18:~$ ssh-keygen -t rsa -C "xxxx@sina.com"

一路回车

marhal@php-ubuntu18:~$ cd /home/marhal/.ssh/
marhal@php-ubuntu18:~/.ssh$ ls
id_rsa  id_rsa.pub  known_hosts
marhal@php-ubuntu18:~/.ssh$ cat id_rsa.pub 
ssh-rsa 密钥内容 xxxxx@sina.com

复制 id_rsa.pub 的内容到代码托管平台添加ssh密钥。

添加以后测试是否成功

marhal@php-ubuntu18:~$ ssh code.aliyun.com
Connection to code.aliyun.com closed by remote host.
Connection to code.aliyun.com closed.

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值