环境linux
利用 pw管理文件 【.netrc】(linux 下路径: /home/username , windows下路径:C:\Users\username)
[ec2-user[ip-99-9-9-99 gitdir]$ git remote -v // 查看remote
origin https://gitlab.com/xxxxx/pj.git (fetch)
origin https://gitlab.com/xxxxx/pj.git (push)
[ec2-user[ip-99-9-9-99 gitdir]$ git fetch origin develop // 每次执行 pull等命令都要输入用户名密码
Username for 'https://gitlab.com': username
Password for 'https://gitlab.com':
[ec2-user[ip-99-9-9-99 ~]$ pwd
/home/ec2-user
[ec2-user[ip-99-9-9-99 ~]$ touch .netrc // 新建文件
[ec2-user[ip-99-9-9-99 ~]$ vim .netrc
写入内容
machine gitlab.com
login username
password somepassword
//复数remote的话,在写一组即可
machine github.com
login username
password somepassword
3,权限变更
[ec2-user[ip-99-9-9-99 ~]$ chmod 600 .netrc
可以更新啦
[ec2-user[ip-99-9-9-99 ~]$ cd gitdir
[ec2-user[ip-99-9-9-99 gitdir]$ git fetch origin develop // 就不会再提示输入用户名密码啦
windows:C:\Users\water.netrc
machine gitlab.com
login usr001
password p@ssw0rd01
machine it-manager.backlog.com
login manageruser
password test
python读取文件
netrc属于标准库,不需要安装
>>> import netrc
>>> auth = netrc.netrc()
>>> username, _, password = auth.authenticators("gitlab.com")
>>> print(username, password)
usr001 p@ssw0rd01
>>> username, _, password = auth.authenticators("it-manager.backlog.com")
>>> print(username, password)
manageruser test
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。