Trying to create SSH connection using Gitlab CI, Error : SSH Permission denied (publickey,password)
Trying to create SSH connection using Gitlab CI, Error : SSH Permission denied (publickey,password)
我在 GitLab 上有一个 Repository 和一个 Private VPS。我想做的是,当我推送到存储库时,我需要 GitLab/ci 脚本来连接 VPS 服务器。
我试过的是
- 登录 VPS 并使用
ssh-keygen
生成 SSH 密钥
- 复制私钥到Gitlab > Settings > CI/CD > 变量 > SSH_PRIVATE_KEY
- 将 public 密钥复制到 Gitlab > 用户首选项 > SSH 密钥
- 并在 gitlab.ci
中使用以下脚本推送提交
- 'which ssh-agent || ( apk add openssh-client )'
# Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)
# add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
- echo "$SSH_PRIVATE_KEY"
- echo "$SSH_PRIVATE_KEY" > key
- chmod 600 key
- ssh-add key
# make dirs
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan -t rsa 1.2.3.4.5 > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
# Remove
- rm key
script:
- ssh user@1.2.3.4.5
=> PS: 1.2.3.4.5 不是真实的 IP 地址 我只是作为例子更改了它。
- 我正在准备的是
user@1.2.3.4.5 : Permission denied (publickey,password).
=> PS: 我的分支或标签不受保护或私有
在脚本测试中,使用:
ssh -Tv user@1.2.3.4.5
这样,您将看到是否使用了名为“key
”的文件。
如果它实际上被命名为 'key'(而不是默认的 id_rsa
),您需要一个 ~/.ssh/config 文件来引用它:
Host destination
Hosname 1.2.3.4.5
User user
IdentityFile ~/.ssh/key
但在这种情况下,URL 调用将是:
ssh -Tv destination
我在 GitLab 上有一个 Repository 和一个 Private VPS。我想做的是,当我推送到存储库时,我需要 GitLab/ci 脚本来连接 VPS 服务器。 我试过的是
- 登录 VPS 并使用
ssh-keygen
生成 SSH 密钥
- 复制私钥到Gitlab > Settings > CI/CD > 变量 > SSH_PRIVATE_KEY
- 将 public 密钥复制到 Gitlab > 用户首选项 > SSH 密钥
- 并在 gitlab.ci 中使用以下脚本推送提交
- 'which ssh-agent || ( apk add openssh-client )'
# Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)
# add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
- echo "$SSH_PRIVATE_KEY"
- echo "$SSH_PRIVATE_KEY" > key
- chmod 600 key
- ssh-add key
# make dirs
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan -t rsa 1.2.3.4.5 > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
# Remove
- rm key
script:
- ssh user@1.2.3.4.5
=> PS: 1.2.3.4.5 不是真实的 IP 地址 我只是作为例子更改了它。
- 我正在准备的是
user@1.2.3.4.5 : Permission denied (publickey,password).
=> PS: 我的分支或标签不受保护或私有
在脚本测试中,使用:
ssh -Tv user@1.2.3.4.5
这样,您将看到是否使用了名为“key
”的文件。
如果它实际上被命名为 'key'(而不是默认的 id_rsa
),您需要一个 ~/.ssh/config 文件来引用它:
Host destination
Hosname 1.2.3.4.5
User user
IdentityFile ~/.ssh/key
但在这种情况下,URL 调用将是:
ssh -Tv destination