SSH 公私钥的基本使用

SSH 公私钥的基本使用

创建密钥

使用 ssh-keygen 生成公私钥
在终端敲入 ssh-keygen 命令,一路一直按回车下去,会把密钥文件放置在默认路径,也就是 ~/.ssh/ 路径下,并且会创建一套空密码验证的密钥文件。

# ssh-keygen
# cd ~/.ssh/
# ls
# cat id_rsa.pub

关联公钥到 Github 账号下

首先复制公钥文件中的内容,也就是 ssh-rsa 开头到 用户名@主机名 这段字符串到 Github, 点击右上角头像的下拉按钮,选择 Settings -> SSH and GPG keys -> New SSH key 到里面。

安装配置 Git 工具

安装 Git

配置用户名与邮箱

使用Git的第一件事就是设置你的名字和email,这些就是你在提交commit时的签名。

[root@VM_0_9_centos .ssh]# git config --global user.name "Scott Chacon"
[root@VM_0_9_centos .ssh]# git config --global user.email "[email protected]"
[root@VM_0_9_centos .ssh]# cat ~/.gitconfig

执行了上面的命令后,会在你的主目录(home directory)建立一个叫 ~/.gitconfig 的文件. 内容一般像下面这样:

[user]
    name = Scott Chacon
    email = [email protected]

:这样的设置是全局设置,会影响此用户建立的每个项目.

如果你想使项目里的某个值与前面的全局设置有区别(例如把私人邮箱地址改为工作邮箱);你可以在项目中使用git
config 命令不带 --global 选项来设置. 这会在你项目目录下的 .git/config 文件增加一节[user]内容(如上所示).

猜你喜欢

转载自www.cnblogs.com/hglibin/p/10049125.html