自建了 gitlab,要如何配置 ssh 的密钥?

302 天前
 gegeligegeligo

用 ssh-keygen 命令创建了密钥,并把公钥复制到了 gitlab 上。接下来要如何配置私钥?

1328 次点击
所在节点    问与答
19 条回复
ahaooahaz
302 天前
ssh-keygen 同时生成了公钥和私钥,私钥只留在机器上,上传公钥之后直接用就可以了
gegeligegeligo
302 天前
@ahaooahaz #1 但是 push 的时候提示 Permission denied (publickey)。不知道是什么原因,这个要怎么排查问题😭
once1mo
302 天前
... ssh-keygen 生成的时候既有公钥也有私钥。
Daniate
302 天前
gitlab 太重了,我选 gitea
IvanLi127
302 天前
ssh -T -v git@your-gitlab.com
IvanLi127
302 天前
ssh -T -v git@your-gitlab.com

看看有没有用上你的私钥。

一个手抖发出去了
haichao0808
302 天前
@gegeligegeligo 是不是贴错 key 文件了,是那个 id_rsa.pub 文件的内容。要不就检查下仓库是否开了 push 权限或者用户权限不对
dontLookAvatar
302 天前
开 ssh 让我上去看看
gegeligegeligo
302 天前
@IvanLi127 #6 这个 git@your-gitlab.com 要怎么改,比如我的服务器地址是 192.168.2.2 ,端口是 30001
storyxc
302 天前
@8888k666 ssh 哥换号了?🤣
storyxc
302 天前
编辑~/.ssh/config

# gitlab
Host gitlab
HostName your-gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/your-gitlab-private-key
IvanLi127
302 天前
@gegeligegeligo #9 ssh -T -v -p 30001 git@192.168.2.2
gegeligegeligo
302 天前
@storyxc #11 还是不行,Permission denied (publickey).
gegeligegeligo
302 天前
@IvanLi127 #12 输出是这样的:
$ ssh -T -v -p 30001 test@192.168.5.235
OpenSSH_9.3p1, OpenSSL 3.1.1 30 May 2023
debug1: Reading configuration data /c/Users/99192/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 192.168.5.235 [192.168.5.235] port 30001.
debug1: Connection established.
debug1: identity file /c/Users/99192/.ssh/id_rsa type -1
debug1: identity file /c/Users/99192/.ssh/id_rsa-cert type -1
debug1: identity file /c/Users/99192/.ssh/id_ecdsa type -1
debug1: identity file /c/Users/99192/.ssh/id_ecdsa-cert type -1
debug1: identity file /c/Users/99192/.ssh/id_ecdsa_sk type -1
debug1: identity file /c/Users/99192/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /c/Users/99192/.ssh/id_ed25519 type 3
debug1: identity file /c/Users/99192/.ssh/id_ed25519-cert type -1
debug1: identity file /c/Users/99192/.ssh/id_ed25519_sk type -1
debug1: identity file /c/Users/99192/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /c/Users/99192/.ssh/id_xmss type -1
debug1: identity file /c/Users/99192/.ssh/id_xmss-cert type -1
debug1: identity file /c/Users/99192/.ssh/id_dsa type -1
debug1: identity file /c/Users/99192/.ssh/id_dsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.2
debug1: compat_banner: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.2 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.5.235:30001 as 'test'
debug1: load_hostkeys: fopen /c/Users/99192/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:hqhfESj5oWFkoqjXnnLjxSYqlDSapKkeNRyW5saL0IM
debug1: load_hostkeys: fopen /c/Users/99192/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host '[192.168.5.235]:30001' is known and matches the ED25519 host key.
debug1: Found key in /c/Users/99192/.ssh/known_hosts:5
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: get_agent_identities: bound agent to hostkey
debug1: get_agent_identities: agent returned 1 keys
debug1: Will attempt key: /c/Users/99192/.ssh/id_ed25519 ED25519 SHA256:LKGgr4p5eDgiBWTvVNCo7zub/B8+Zlt3Xz6Epy921LI agent
debug1: Will attempt key: /c/Users/99192/.ssh/id_rsa
debug1: Will attempt key: /c/Users/99192/.ssh/id_ecdsa
debug1: Will attempt key: /c/Users/99192/.ssh/id_ecdsa_sk
debug1: Will attempt key: /c/Users/99192/.ssh/id_ed25519_sk
debug1: Will attempt key: /c/Users/99192/.ssh/id_xmss
debug1: Will attempt key: /c/Users/99192/.ssh/id_dsa
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /c/Users/99192/.ssh/id_ed25519 ED25519 SHA256:LKGgr4p5eDgiBWTvVNCo7zub/B8+Zlt3Xz6Epy921LI agent
debug1: Authentications that can continue: publickey
debug1: Trying private key: /c/Users/99192/.ssh/id_rsa
debug1: Trying private key: /c/Users/99192/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/99192/.ssh/id_ecdsa_sk
debug1: Trying private key: /c/Users/99192/.ssh/id_ed25519_sk
debug1: Trying private key: /c/Users/99192/.ssh/id_xmss
debug1: Trying private key: /c/Users/99192/.ssh/id_dsa
debug1: No more authentication methods to try.
test@192.168.5.235: Permission denied (publickey).
gegeligegeligo
302 天前
不知道为什么提示了 Host '[192.168.5.235]:30001' is known and matches the ED25519 host key ,但是还是 Permission denied
gegeligegeligo
302 天前
😭😭😭help me 这是为什么
ray1980
302 天前
~/.ssh/config 文件的配置里加 User git
jim9606
301 天前
ssh 用户名固定是 git ,不会是别的用户名,通常不能省略。
ssh -T -v -p 30001 git@192.168.5.235
看上去私钥文件没放错地方 /c/Users/99192/.ssh/id_ed25519 ,你要上传的是 /c/Users/99192/.ssh/id_ed25519.pub
yuningWang8
278 天前
之前也遇到了同样的问题。不知道楼主解决了没有。你是不是部署的时候,修改了 gitlab 的 22 端口?如果是的话,要么改回 22 端口。要么修改一下项目的 remote 地址,指定端口号,例如:ssh://git@xxxxxx:2222/abc/def 2222 是你修改的端口号。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1011831

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX