美文网首页
Git设置用户名密码并设置ssh秘钥

Git设置用户名密码并设置ssh秘钥

作者: 我的章鱼小丸子呢 | 来源:发表于2020-09-17 11:36 被阅读0次

1、查看git的配置列表

我们可以先查看一下git的配置列表:

git config --list

如果没有配置东西,应该是空的。照着下面配置完成后,你可以再试一下该命令,就会出现一系列配置信息。

2、进行用户名密码配置

(1)命令行配置

git config --global user.name  "username"  
git config --global user.email  "email"

可将username和email换成github(或者其它类似远程仓库)的用户名和密码。

(1.1) 全局变量

--global 表示全局的,即当前用户都有效,该配置会出现在 ~/.gitconfig 文件中,~表示当前用户的目录,比如我的是:C:\Users\username.gitconfig ,打开该文件你会发现如下图所示的内容:

全局变量

对比一下,你应该就知道上面的配置命令是怎么起作用的吧(其它配置命令也是这个意思!)。(注:该文件#开头的行是注释,为了方便理解,你可以自己添加一些注释信息)

全局变量

(1.2)局部变量

既然有全局的,那么肯定有局部的啊!局部的是不加 --global 的,如下:

 git config  user.name  "username"  
 git config  user.email  "email"

局部是只对当前仓库起效的,它的配置信息会在当前仓库根目录/.git/config文件下:

image

注意:局部变量覆盖全局变量!!!和编程语言里面的变量关系是一样的。

(2)修改对应文件进行配置

相信看了上面的补充内容之后,你应该已经了解这两个配置命令的作用了吧,所以这里就不详讲了,你找到对应文件,该相关设置就好了。

3、设置SSH秘钥

(1)新打开一个终端输入

ssh 
ssh-keygen

结果如下:

C:\Users\yaqin>ssh
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
           [-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
           [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
           [-i identity_file] [-J [user@]host[:port]] [-L address]
           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
           [-Q query_option] [-R address] [-S ctl_path] [-W host:port]
           [-w local_tun[:remote_tun]] destination [command]

C:\Users\yaqin>ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\yaqin/.ssh/id_rsa):
Created directory 'C:\Users\yaqin/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\yaqin/.ssh/id_rsa.
Your public key has been saved in C:\Users\yaqin/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:qid/Ht5meUuXLqOQrSyPI9+vJ+WYH05wugElD34Tn0k yaqin@DESKTOP-0HK8SQ0
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|                 |
|     hhhhh   |
|     . = + o     |
|      o S =      |
|       + B.    . |
|      . *=+.. o  |
|    o.+==X*o+o   |
|    .*+*XO*o.+.  |
+----[SHA256]-----+

(2)添加gitlib/hub 的ssh key

登录gitlib/github 点击头像选择settings
选择左侧菜单SSH and GPG keys ;点击右上角的NEW SSH key
新建ssh 链接。
TiTle 可随意填写
Key 将上一步生成的 id_rsa.pub文件 的内容全部复制到此处

新增ssh

4、修改已配置的信息

假如配置后,发现有信息配置错了,如何进行修改?

(1)用命令修改

这里演示修改本地仓库的用户名和邮箱:

git config --replace-all user.name "name"
git config --replace-all user.email "123@qq.com"

修改后是这样的:

image

(2)修改对应文件进行修改

这个应该不用讲了。

5、git config命令的功能列表

(1)git config

我们直接输入git config,就可以看到简单的命令列表了:

C:\Users\yaqin>git config
usage: git config [<options>]

Config file location
    --global              use global config file
    --system              use system config file
    --local               use repository config file
    --worktree            use per-worktree config file
    -f, --file <file>     use given config file
    --blob <blob-id>      read config from given blob object

Action
    --get                 get value: name [value-regex]
    --get-all             get all values: key [value-regex]
    --get-regexp          get values for regexp: name-regex [value-regex]
    --get-urlmatch        get value specific for the URL: section[.var] URL
    --replace-all         replace all matching variables: name value [value_regex]
    --add                 add a new variable: name value
    --unset               remove a variable: name [value-regex]
    --unset-all           remove all matches: name [value-regex]
    --rename-section      rename section: old-name new-name
    --remove-section      remove a section: name
    -l, --list            list all
    -e, --edit            open an editor
    --get-color           find the color configured: slot [default]
    --get-colorbool       find the color setting: slot [stdout-is-tty]

Type
    -t, --type <>         value is given this type
    --bool                value is "true" or "false"
    --int                 value is decimal number
    --bool-or-int         value is --bool or --int
    --path                value is a path (file or directory name)
    --expiry-date         value is an expiry date

Other
    -z, --null            terminate values with NUL byte
    --name-only           show variable names only
    --includes            respect include directives on lookup
    --show-origin         show origin of config (file, standard input, blob, command line)
    --show-scope          show scope of config (worktree, local, global, system, command)
    --default <value>     with --get, use default value when missing entry

(2)git config --help

这个命令默认打开本地git安装目录下的G:\Git\mingw64\share\doc\git-doc\下的详细的说明文档(这里G:\Git为安装目录),这个是详细介绍命令的作用(上面的那个只是简介)。

样例截图:

image

延伸:其它命令你也可以通过添加 --help 参数来打开命令的相关文档说明,如 git diff --help,……

相关文章

  • 配置Git

    进入Git Bash 设置用户名 设置邮箱 配置SSH免密登录 查看秘钥 绑定Gitee 测试是否成功

  • Git设置用户名密码并设置ssh秘钥

    1、查看git的配置列表 我们可以先查看一下git的配置列表: 如果没有配置东西,应该是空的。照着下面配置完成后,...

  • 【工具安装和配置】 GIT配置

    //换行符不转换设置 //设置用户名 //设置邮箱 //生成秘钥 //将秘钥添加到SSH KEY登录GitLab或...

  • git ssh key 设置

    git ssh key 设置 设置完成后,git pull,push等命令就不需要再输入用户名和密码了 生成公钥,...

  • Git

    git 一. 使用前准备 设置SSH Key 过程需要创建密码。id_rsa 文件是私有秘钥,id_rsa.pud...

  • git的一些操作

    添加git用户并设置密码 创建公钥保存文件 每行一个公钥文件 客户端创建密码命令 位置在C:\Users\用户名\...

  • Linux 配置 Git 过程备份

    安装 git 配置用户名和邮箱 生成 SSH 秘钥 然后,回车 3 次。 Windows 下使用: 查看公钥并复...

  • git的安装和使用

    官网-安装 1、用户认证 email和用户名 2、远程github 设置秘钥 ssh-keyge...

  • 常用Git命令

    设置本机绑定SSH公钥,实现免密码登录 git config -l 查看配置 git config --syste...

  • 取消 SSH 私钥密码

    前言 生成 SSH 秘钥时,会让你输入私钥的密码,直接回车则意为不设密码,如果设置了私钥密码,每次使用 SSH 进...

网友评论

      本文标题:Git设置用户名密码并设置ssh秘钥

      本文链接:https://www.haomeiwen.com/subject/nqzcyktx.html