skip to content
Logo 三七の小站

备份由 github 搭建的图床

/ 3 min read

git clone 到本地

1、设置SSH密钥对

1.1、终端运行,生成密钥对

Terminal window
ssh-keygen -t rsa -b 4096

passphrase 为空即可

1.2、在github官网上添加密钥

上一步生成成功后,把 .ssh文件夹下的 id_rsa.pub 内容拷贝到 github 新建的 SSH keys 中

2、github连接

电脑上终端运行:

sanqi730/images2.git
# git init
# git remote add main git@github.com:sanqi730/images2.git
git clone git@github.com:sanqi730/images2.git
git checkout img
git config user.name "Your Name"
git config user.email "1254751767@qq.com"

3. 多github账号管理

如果你有多个 GitHub 账号,并且每个账号都使用不同的 SSH 密钥,你可以通过配置 SSH 客户端来使用不同的 SSH 密钥对应不同的 GitHub 账号。你可以通过以下步骤来配置:

  1. 生成不同的 SSH 密钥对: 为每个 GitHub 账号生成一个独立的 SSH 密钥对。例如:

    Terminal window
    ssh-keygen -t rsa -C "your_email1@example.com" -f ~/.ssh/id_rsa_github_account1
    ssh-keygen -t rsa -C "your_email2@example.com" -f ~/.ssh/id_rsa_github_account2
  2. 将 SSH 公钥添加到相应的 GitHub 账号: 在 GitHub 上的每个账号设置页面中添加相应的 SSH 公钥。

  3. 创建 SSH 配置文件: 编辑或创建 ~/.ssh/config 文件,添加以下内容来配置不同的 SSH 密钥对应不同的 GitHub 账号:

    # GitHub Account 1
    Host github-account1.github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_github_account1
    # GitHub Account 2
    Host github-account2.github.com
    HostName github.com
    User git
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_github_account2
  4. 克隆或设置远程仓库时使用配置的Host: 当你需要克隆或设置远程仓库时,使用配置文件中的 Host 名称。例如:

    Terminal window
    git clone git@github-account1.github.com:username/repo.git # 会提示输入yes
    git remote add origin git@github-account2.github.com:username/repo.git

通过上述步骤,你可以轻松地管理多个 GitHub 账号的 SSH 密钥,而无需每次切换不同的密钥。

!! 如果使用docker, 请给予权限

chmod 600 /config/.ssh/id_rsa_zouzonghao