自建了 gitlab,要如何配置 ssh 的密钥? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
gegeligegeligo

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

  •  
  •   gegeligegeligo Jan 26, 2024 2378 views
    This topic created in 821 days ago, the information mentioned may be changed or developed.

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

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

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

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

    # gitlab
    Host gitlab
    HostName your-gitlab.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/your-gitlab-private-key
    IvanLi127
        12
    IvanLi127  
       Jan 26, 2024
    @gegeligegeligo #9 ssh -T -v -p 30001 [email protected]
    gegeligegeligo
        13
    gegeligegeligo  
    OP
       Jan 26, 2024
    @storyxc #11 还是不行,Permission denied (publickey).
    gegeligegeligo
        14
    gegeligegeligo  
    OP
       Jan 26, 2024
    @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
       Jan 26, 2024
    不知道为什么提示了 Host '[192.168.5.235]:30001' is known and matches the ED25519 host key ,但是还是 Permission denied
    gegeligegeligo
        16
    gegeligegeligo  
    OP
       Jan 26, 2024
    help me 这是为什么
    ray1980
        17
    ray1980  
       Jan 27, 2024
    ~/.ssh/config 文件的配置里加 User git
    jim9606
        18
    jim9606  
       Jan 27, 2024
    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  
       Feb 19, 2024
    之前也遇到了同样的问题。不知道楼主解决了没有。你是不是部署的时候,修改了 gitlab 的 22 端口?如果是的话,要么改回 22 端口。要么修改一下项目的 remote 地址,指定端口号,例如:ssh://git@xxxxxx:2222/abc/def 2222 是你修改的端口号。
    About     Help     Advertise     Blog     API     FAQ     Solana     3574 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 50ms UTC 04:54 PVG 12:54 LAX 21:54 JFK 00:54
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86