V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
gegeligegeligo
V2EX  ›  问与答

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

  •  
  •   gegeligegeligo · 304 天前 · 1337 次点击
    这是一个创建于 304 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    19 条回复    2024-02-19 15:15:31 +08:00
    ahaooahaz
        1
    ahaooahaz  
       304 天前
    ssh-keygen 同时生成了公钥和私钥,私钥只留在机器上,上传公钥之后直接用就可以了
    gegeligegeligo
        2
    gegeligegeligo  
    OP
       304 天前
    @ahaooahaz #1 但是 push 的时候提示 Permission denied (publickey)。不知道是什么原因,这个要怎么排查问题😭
    once1mo
        3
    once1mo  
       304 天前
    ... ssh-keygen 生成的时候既有公钥也有私钥。
    Daniate
        4
    Daniate  
       304 天前   ❤️ 1
    gitlab 太重了,我选 gitea
    IvanLi127
        5
    IvanLi127  
       304 天前
    ssh -T -v git@your-gitlab.com
    IvanLi127
        6
    IvanLi127  
       304 天前
    ssh -T -v git@your-gitlab.com

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

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

    # gitlab
    Host gitlab
    HostName your-gitlab.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/your-gitlab-private-key
    IvanLi127
        12
    IvanLi127  
       304 天前
    @gegeligegeligo #9 ssh -T -v -p 30001 [email protected]
    gegeligegeligo
        13
    gegeligegeligo  
    OP
       304 天前
    @storyxc #11 还是不行,Permission denied (publickey).
    gegeligegeligo
        14
    gegeligegeligo  
    OP
       304 天前
    @IvanLi127 #12 输出是这样的:
    $ ssh -T -v -p 30001 [email protected]
    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: [email protected] MAC: <implicit> compression: none
    debug1: kex: client->server cipher: [email protected] 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,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected]>
    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.
    [email protected]: Permission denied (publickey).
    gegeligegeligo
        15
    gegeligegeligo  
    OP
       304 天前
    不知道为什么提示了 Host '[192.168.5.235]:30001' is known and matches the ED25519 host key ,但是还是 Permission denied
    gegeligegeligo
        16
    gegeligegeligo  
    OP
       304 天前
    😭😭😭help me 这是为什么
    ray1980
        17
    ray1980  
       303 天前
    ~/.ssh/config 文件的配置里加 User git
    jim9606
        18
    jim9606  
       303 天前
    ssh 用户名固定是 git ,不会是别的用户名,通常不能省略。
    ssh -T -v -p 30001 [email protected]
    看上去私钥文件没放错地方 /c/Users/99192/.ssh/id_ed25519 ,你要上传的是 /c/Users/99192/.ssh/id_ed25519.pub
    yuningWang8
        19
    yuningWang8  
       280 天前
    之前也遇到了同样的问题。不知道楼主解决了没有。你是不是部署的时候,修改了 gitlab 的 22 端口?如果是的话,要么改回 22 端口。要么修改一下项目的 remote 地址,指定端口号,例如:ssh://git@xxxxxx:2222/abc/def 2222 是你修改的端口号。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1023 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:02 · PVG 05:02 · LAX 13:02 · JFK 16:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.