Store login credentials in CLI

Every time I push to GitLab in the CLI I am asked to enter my username and password. I have a SSH key generated and added into my GitLab profile. How do I store my login credentials in Git so GitLab doesn’t ask for my username and password?

Hi @dylanrod & welcome to the community :wave: Please try these 3 troubleshooting items and post their output here.

Hi @katrinleinweber and thank you! Glad to be here. I am still to new to this. I ran the debug connection command and here is my output:

ssh -Tv git@gitlab.com                                                                                                                                              ✔ 
OpenSSH_8.8p1, OpenSSL 1.1.1l  24 Aug 2021
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to gitlab.com [172.65.251.78] port 22.
debug1: Connection established.
debug1: identity file /home/dylanrodriguez/.ssh/id_rsa type 0
debug1: identity file /home/dylanrodriguez/.ssh/id_rsa-cert type -1
debug1: identity file /home/dylanrodriguez/.ssh/id_dsa type -1
debug1: identity file /home/dylanrodriguez/.ssh/id_dsa-cert type -1
debug1: identity file /home/dylanrodriguez/.ssh/id_ecdsa type -1
debug1: identity file /home/dylanrodriguez/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/dylanrodriguez/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/dylanrodriguez/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/dylanrodriguez/.ssh/id_ed25519 type -1
debug1: identity file /home/dylanrodriguez/.ssh/id_ed25519-cert type -1
debug1: identity file /home/dylanrodriguez/.ssh/id_ed25519_sk type -1
debug1: identity file /home/dylanrodriguez/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/dylanrodriguez/.ssh/id_xmss type -1
debug1: identity file /home/dylanrodriguez/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.8
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.9p1 Debian-10+deb10u2
debug1: compat_banner: match: OpenSSH_7.9p1 Debian-10+deb10u2 pat OpenSSH* compat 0x04000000
debug1: Authenticating to gitlab.com:22 as 'git'
debug1: load_hostkeys: fopen /home/dylanrodriguez/.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:eUXGGm1YGsMAS7vkcx6JOJdOGHPem5gQp4taiCfCLB8
debug1: load_hostkeys: fopen /home/dylanrodriguez/.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 'gitlab.com' is known and matches the ED25519 host key.
debug1: Found key in /home/dylanrodriguez/.ssh/known_hosts:1
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: Will attempt key: /home/dylanrodriguez/.ssh/id_rsa RSA SHA256:LEarXZDOIgOY/v5nTYUQanVwL5BR+R45kSBjW4/5SSU
debug1: Will attempt key: /home/dylanrodriguez/.ssh/id_dsa 
debug1: Will attempt key: /home/dylanrodriguez/.ssh/id_ecdsa 
debug1: Will attempt key: /home/dylanrodriguez/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /home/dylanrodriguez/.ssh/id_ed25519 
debug1: Will attempt key: /home/dylanrodriguez/.ssh/id_ed25519_sk 
debug1: Will attempt key: /home/dylanrodriguez/.ssh/id_xmss 
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: /home/dylanrodriguez/.ssh/id_rsa RSA SHA256:LEarXZDOIgOY/v5nTYUQanVwL5BR+R45kSBjW4/5SSU
debug1: Server accepts key: /home/dylanrodriguez/.ssh/id_rsa RSA SHA256:LEarXZDOIgOY/v5nTYUQanVwL5BR+R45kSBjW4/5SSU
Authenticated to gitlab.com ([172.65.251.78]:22) using "publickey".
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: filesystem full
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: client_input_hostkeys: searching /home/dylanrodriguez/.ssh/known_hosts for gitlab.com / (none)
debug1: client_input_hostkeys: searching /home/dylanrodriguez/.ssh/known_hosts2 for gitlab.com / (none)
debug1: client_input_hostkeys: hostkeys file /home/dylanrodriguez/.ssh/known_hosts2 does not exist
debug1: client_input_hostkeys: no new or deprecated keys from server
debug1: Remote: /authorized_keys %u %k:1: key options: command user-rc
debug1: Remote: /authorized_keys %u %k:1: key options: command user-rc
Welcome to GitLab, @dylanrod24!
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2756, received 2720 bytes, in 0.2 seconds
Bytes per second: sent 14357.5, received 14170.0
debug1: Exit status 0

@dylanrod your debug output above shows that it connected. So you should be able to clone fine, by:

git clone git@gitlab.com/myusername/myprojectname

Once cloned, inside the cloned directory will be a .git/config file and you can take a look at this and it should show how it’s cloned in terms of the git@gitlab.com part. Then standard pull/push should work without using passwords anymore. Providing of course, that when you created your SSH key you didn’t create the key with a password. Otherwise, if so, you still have to use a password for your SSH key to work.

1 Like

Ah okay. So I would have to clone a project then I get a a gitlab/git config file and my gitlab login will not longer be needed in cli when pushing? I did not create a password when I created my SSH key.

Thanks for already replying @iwalker :slight_smile:

I did not create a password when I created my SSH key.

Then git should not prompt you for any password. Note, though, that that password would be different (local) from the one GitLab would ask you about (account).

my gitlab login will not longer be needed in cli when pushing?

Not if the push/pull URLs in cat .git/config (or git remove -v) start with git@gitlab.com AND your SSH key isn’t protected by a local password.

Cheers!