远程仓库

查看远程仓库

git remote -v

修改远程仓库

git remote set-url origin https://xxx/xxx/xxx.git

初始化设置

git config --global core.autocrlf input //

git config user.name "姓名(用户id)"
git config user.email "mail@xxx.com"

如果是在Windows系统上,把它设置成true(默认配置),这样当签出代码时,LF会被转换成CRLF:
git config --global core.autocrlf true

如果是在Windows系统上,把它设置成input,这样当签出代码时,LF不会被转换成CRLF,提交时会将CRLF转成LF
git config --global core.autocrlf input

检出和提交都不做处理

git config --global core.autocrlf false

忽略ssl验证

git config --global http.sslVerify false

git配置ssh步骤

配置文件说明

authorized_keys

作用:这个文件位于服务器端,用来存储允许访问该服务器的公钥。服务器会检查连接请求中提供的公钥是否在这个文件中,如果有匹配的公钥,则允许连接。

配置方法:你需要把你本地生成的公钥(通常是 ~/.ssh/id_rsa.pub 或 ~/.ssh/id_ed25519.pub)复制到远程服务器的 ~/.ssh/authorized_keys 文件中。每个公钥占一行。

将本地公钥追加到服务器的 authorized_keys 文件中
cat ~/.ssh/id_rsa.pub | ssh user@server 'cat >> ~/.ssh/authorized_keys'

config

作用:这个文件位于客户端,用来配置 SSH 客户端的行为,包括主机别名、使用的密钥文件、端口等。

配置方法:你可以在这个文件中为不同的服务器配置不同的选项。例如:

Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa

Host myserver
HostName example.com
User myuser
Port 2222
IdentityFile ~/.ssh/id_ed25519

这样,在使用 ssh github.comssh myserver 时,SSH 会自动使用你在 config 文件中配置的选项。

known_hosts

作用:这个文件位于客户端,用来记录你曾经连接过的服务器的主机密钥。当你第一次连接某个服务器时,SSH 会把该服务器的主机密钥添加到这个文件中。以后每次连接时,SSH 会检查该主机密钥是否与记录中的一致,以防止中间人攻击。

配置方法:这个文件通常不需要手动配置,SSH 会自动管理。不过,如果你想手动添加一个主机密钥,可以使用 ssh-keyscan 命令。例如:

获取 example.com 的主机密钥并添加到 known_hosts 文件中
ssh-keyscan example.com >> ~/.ssh/known_hosts

github配置ssh

假设你要配置 Git 使用 SSH 连接到 GitHub,下面是详细的操作步骤:

  1. 生成 SSH 密钥对:
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    按提示完成操作,这会在 ~/.ssh/ 目录下生成 id_rsa(私钥)和 id_rsa.pub(公钥)。
  2. 将公钥添加到 GitHub:
  3. 登录 GitHub。
    进入 Settings -> SSH and GPG keys -> New SSH key。
    将 id_rsa.pub 文件的内容复制到 GitHub 的公钥输入框中,并保存。
  4. 配置 ~/.ssh/config 文件(如果没有这个文件,可以新建):
    Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa
  5. 测试连接:
    ssh -T git@github.com
    如果配置正确,你会看到类似 “Hi username! You've successfully authenticated...” 的提示