Github 使用PAT(Personal Access Token)后的命令行登录
在Github上启用PAT
命令行下使用git push不能再直接使用用户名密码, 在输入密码的地方需要使用PAT来代替. 具体的创建步骤为
https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token
如果只是用于提交代码, 勾选repo部分即可, 对于大部分场景, 可以加上这几个权限gist, read:org, repo, workflow
Windows 用户
控制面板 => Credential Manager => Windows Credentials
- 找到 git:https://github.com => 编辑 => 将 Password 替换成在 GitHub 上生成的 Personal Access Token => OK
- 如果没有 git:https://github.com , 点击 Add a generic credential => Internet 地址填写 git:https://github.com , 输入用户名和 Personal Access Token => OK
之后在git中做如下设置
git config --local credential.helper wincred
Linux 用户
首先给git配置上 username 和 email
$ git config --global user.name "your_github_username"
$ git config --global user.email "your_github_email"
$ git config -l
然后用git连接 GitHub. 例如:
$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
> Cloning into `Spoon-Knife`...
$ Username for 'https://github.com' : username
$ Password for 'https://github.com' : 这里输入 personal access token
然后用下面的命令, 将这个token加入缓存
$ git config --global credential.helper cache
你可以随时使用下面的命令删除缓存
$ git config --global --unset credential.helper
$ git config --system --unset credential.helper
可以用-v参数验证一下
$ git pull -v
Linux/Debian可以用下面的命令Clone:
git clone https://<tokenhere>@github.com/<user>/<repo>.git
开启双因子认证后命令行登入Github
在GitHub开启双因子后, 以前的登录方式不行了
mote-pad$ git pull
Username for 'https://github.com': someone
Password for 'https://someone@github.com':
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/someone/mote-pad.git/'
搜了下, 命令行登录需要通过GitHub CLi 或者 Git Credential Manager, 当前环境还没安装
mote-pad$ git credential-manager -h
git: 'credential-manager' is not a git command. See 'git --help'.
安装步骤
从 https://github.com/git-ecosystem/git-credential-manager/releases 下载 .deb 包(我用的Ubuntu环境)然后安装
# download
wget https://github.com/git-ecosystem/git-credential-manager/releases/download/v2.4.1/gcm-linux_amd64.2.4.1.deb
# install
sudo dpkg -i gcm-linux_amd64.2.4.1.deb
# configurate
git-credential-manager configure
# check
git credential-manager -h
设置存储方式
plaintext 明文方式, 默认存到 /home/[username]/.gcm/store/git/https/github.com/someone.credential, 这种方式不够安全
# cd到项目目录下, 用--local设为局部设置
git config --local credential.credentialStore plaintext
这时候就可以用github账号登录了
# 查看保存的github账号, 当前为空
git credential-manager github list
# 登录, 不需要用户名, 直接用 PAT Token
git credential-manager github login
Select an authentication method for 'https://github.com/':
1. Device code (default)
2. Personal access token
option (enter for default): 2
Enter GitHub personal access token for 'https://github.com/'...
Token:
# 检查
git credential-manager github list
someone
换成gpg存储
参考 https://github.com/git-ecosystem/git-credential-manager/blob/main/docs/credstores.md
初始化 gpg key, 会让输入name和email, name 就是 user id, 可以用于后面的pass init
$ gpg --gen-key
...
Real name: someone
Email address: someone@outlook.com
You selected this USER-ID:
"someone <someone@outlook.com>"
Change (N)ame, (E)mail, or (O)kay/(Q)uit? o
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: key 2EDDD89402CB8758 marked as ultimately trusted
gpg: directory '/home/someone/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/home/someone/.gnupg/openpgp-revocs.d/771DB7B3382BA257BE64DB6F2EDDD89402CB8758.rev'
public and secret key created and signed.
pub rsa3072 2023-11-09 [SC] [expires: 2025-11-08]
771DB7B3382BA257BE64DB6F2EDDD89402CB8758
uid someone <someone@outlook.com>
sub rsa3072 2023-11-09 [E] [expires: 2025-11-08]
中间会创建一个口令, 用于日常验证
用这个user id创建pass
pass init someone
mkdir: created directory '/home/someone/.password-store/'
Password store initialized for someone
git config 换成 gpg 存储
git config --local credential.credentialStore gpg
之后第一次使用, 需要用APT登录, 后续登录, 需要使用之前创建的口令, 和sudo一样有缓存不需要每次验证
Github 使用PAT(Personal Access Token)后的命令行登录的更多相关文章
- rpm方式安装MySQL后在命令行登录报错:ERROR 1045 (28000): Unknown error 1045
1.通过https://mirrors.tuna.tsinghua.edu.cn镜像源安装了MySQL5.7.22 rpm -ivh --force --nodeps https://mirrors. ...
- github & personal access token
github & personal access token OAuth https://github.com/xgqfrms/webtrc-in-action/issues/1#issuec ...
- [2018-05-27]配置VSTS认证方式使用Personal Access Token
本文介绍下如何配置VSTS(visual studio team service,其实就是微软SaaS版的TFS)通过Personal Access Token访问其下的Git代码库. 问题 使用gi ...
- gitlab克隆报错:remote: HTTP Basic: Access denied;remote: You must use a personal access token with ‘api’ scope for Git over HTTP.
错误: remote: HTTP Basic: Access denied remote: You must use a personal access token with ‘api’ scope ...
- 安装了nodejs后在命令行运行npm报错
安装了nodejs后在命令行运行npm报错:Error: Cannot find module 'internal/util/types' 解决方法:删除目录“C:\Users\mengxiaobo\ ...
- 安装zsh后出现命令行无法识别已安装的node
安装zsh之后,在命令行输入 node -v,会出现 command not found: node. 出现原因是:使用bash输入终端指令识别得是~/.bash_profile,而安装zsh则无法识 ...
- Linux普通用户登录后,命令行提示:-bash-4.1$ ,原因分析及解决
原文 有时候在使用用户登陆Linux系统时会发现,命令行提示符成了:-bash-4.1$,不显示用户名,路径信息. 原因:用户家目录里面与环境变量有关的文件被删除所导致的 也就是这俩文件:.bash_ ...
- 配置github的SSH key及GitHub项目上传方式一——使用终端命令行
GitHub是一个开源的大仓库,我们经常从github上下载项目进行学习和研究,下面是一个完整的步骤——往GitHub上传一个新项目. 一.注册GitHub账号 1.注册GitHub账号,地址:htt ...
- win10系统 安装好composer后 cmd 命令行下输入composer提示不是内部或外部的命令,也不是可执行的程序或批处理文件
在 windows CMD 下运行composer 出现错误提示: 不是内部或外部命令,也不是可运行的程序或批处理文件,这是因为没有配置 PATH 环境变量. 以 win10 为例,找到此电脑右击选择 ...
- macOS 升级后重装命令行工具的问题
问题背景 最近升级个人macbook 从 10.13 到 10.14 在终端输入 git 不能用了,发现是重装操作系统后原来的 Command Line Tools 被自动卸载了, 采用 xcode- ...
随机推荐
- 【rt-thread】构建自己的项目工程 -- 初始篇
现以stm32f429igt6芯片的板子 & Keil5编译环境为例,记述构建适配自己板子的rt-thread工程的过程 1.拿到rt-thread源码,进入bsp/stm32/librari ...
- SpringMVC04——数据处理及跳转
结果跳转 1.ModelAndView 设置ModelAndView对象,根据view的名称,和试图解析器跳到指定的页面. 页面:{视图解析器前缀} + viewName + {视图解析器后缀} &l ...
- [转帖]ioping测试
https://www.cnblogs.com/ishmaelwanglin/p/10839702.html 一个实时显示磁盘io延时的工具,以类似ping 的输出一样展示输出结果 常用参数: -c ...
- 物理机和虚拟机上CPU睿频的区别
物理机和虚拟机上CPU睿频的区别 关于睿频 睿频是指当启动一个运行程序后,处理器会自动加速到合适的频率, 而原来的运行速度会提升 10%~20% 以保证程序流畅运行的一种技术. 一般max的睿频不能超 ...
- Python学习之五_字符串处理生成查询SQL
Python学习之五_字符串处理生成查询SQL 前言 昨天想给同事讲解一下获取查询部分表核心列信息的SQL方法 也写好了一个简单文档. 但是感觉不是很优雅. 最近两三天晚上一直在学习Python. 想 ...
- [转帖]sudo 命令_su、sudo、sudo su、sudo -i的用法和区别
sudo 命令 1.sudo 简介 sudo是linux系统管理指令,是允许系统管理员让普通用户执行一些或者全部的root命令的一个工具,如halt,reboot,su等等.这样不仅减少了root用户 ...
- MySQL in Windows安装以及异名恢复的简单过程
下载相关 建议获取最新版本的Mysql数据库 可以获取 zip 格式的安装文件 https://dev.mysql.com/downloads/mysql/ 或者获取 msi 格式的安装文件 http ...
- date的命令使用.
date命令的使用 1.直接用date命令显示日期时间 在命令行中输入date然后回车,显示结果"Wed Aug 7 08:58:07 CST 2019".这是系统根据设定的时区显 ...
- 信创-飞腾CPU路线图
- 基于eBPF的微服务网络安全(Cilium 1)
基于eBPF的微服务网络安全 翻译自:Network security for microservices with eBPF 一些开源的kubernetes工具已经开始使用eBPF,这些工具大多数与 ...