<?xml version="1.0" encoding="utf-8"?>

<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  <generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator>
  <link href="https://www.softwaredeveloper.blog/tag/linux/feed.xml" rel="self" type="application/atom+xml" />
  <link href="https://www.softwaredeveloper.blog/tag/linux" rel="alternate" type="text/html" hreflang="en" />
  <updated>2026-02-26T06:03:45+00:00</updated>
  <id>https://www.softwaredeveloper.blog/tag/linux</id>

  
  
  

  
    <title type="html">Software Developer Blog | </title>
  

  
    <subtitle>Software craftsmanship and agile project management</subtitle>
  

  

  
    
      
    
  

  
  

  
    
    
    
    <entry>
      <title type="html">Store Git SSH key pair in Linux with Libsecret to skip asking for credentials</title>
      
        
         
        <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://www.softwaredeveloper.blog/assets/images/shell-key.jpg"/>
        <media>https://www.softwaredeveloper.blog/assets/images/shell-key.jpg</media>
        <media><img src="https://www.softwaredeveloper.blog/assets/images/shell-key.jpg"/></media>
        <media url="https://www.softwaredeveloper.blog/assets/images/shell-key.jpg" />
        <img src="https://www.softwaredeveloper.blog/assets/images/shell-key.jpg" />
        <image>
          <url>https://www.softwaredeveloper.blog/assets/images/shell-key.jpg</url>
          <title>Store Git SSH key pair in Linux with Libsecret to skip asking for credentials</title>
          <link>https://www.softwaredeveloper.blog/store-git-ssh-credentials-in-linux</link>
        </image>
      
      <link href="https://www.softwaredeveloper.blog/store-git-ssh-credentials-in-linux" rel="alternate" type="text/html" title="Store Git SSH key pair in Linux with Libsecret to skip asking for credentials" />
      <published>2019-11-04T10:00:00+00:00</published>
      <updated>2020-03-06T08:00:00+00:00</updated>
      <id>https://www.softwaredeveloper.blog/store-git-ssh-credentials-in-linux</id>
      <content type="html" xml:base="https://www.softwaredeveloper.blog/store-git-ssh-credentials-in-linux">&lt;p&gt;If you have to connect to Git via SSH, your usual credential manager may be not enough. Read how to avoid entering password every time on your Linux device.&lt;/p&gt;

&lt;p&gt;I have already introduced &lt;a href=&quot;https://www.softwaredeveloper.blog/git-credential-storage-libsecret&quot;&gt;Libsecret Git credential manager&lt;/a&gt;, which works fine if you connect to remote repo via http(s),
which is what we usually do. But sometimes we are forced to use SSH protocol, and once again we need to write password every time we interact with remote repo. 
Luckily it can be solved in secure way quite easily, but unfortunately descriptions which I found on the internet are not clear, moreover usually skip securing private keys. 
My goal is to explain it in this article in simple words, so you can apply it and understand what you do.&lt;/p&gt;

&lt;h2 id=&quot;how-automate-ssh-connection-works&quot;&gt;How automate SSH connection works&lt;/h2&gt;
&lt;p&gt;Mechanism which is used in SSH to automate connections is really simple.
You generate public-private keys pair (those keys are not related to credentials nor any other data), hide private key with you and share public key with server.
Then when you try to connect to server, your clients uses private key as prove that you’re allowed to connect - that’s it.&lt;/p&gt;

&lt;p&gt;It sounds quite magically, but it’s really simple. Those keys are just text files, stored somewhere on your device, usually in &lt;em&gt;~/.ssh&lt;/em&gt; directory.
They are not related to any data, it’s just a pair which suits each other, in mathematical meaning, you generate it with &lt;em&gt;OpenSSH&lt;/em&gt; tool.
Look at this example (with default file names &lt;em&gt;id_rsa&lt;/em&gt; and &lt;em&gt;id_rsa.pub&lt;/em&gt;):&lt;/p&gt;

&lt;p&gt;Private key file: &lt;em&gt;~/.ssh/id_rsa&lt;/em&gt;&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp
wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5
1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh
3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2
pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX
GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il
AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF
L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k
X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl
U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=
-----END RSA PRIVATE KEY-----
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Public key file: &lt;em&gt;~/.ssh/id_rsa.pub&lt;/em&gt;&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0
FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/
3j+skZ6UtW+5u09lHNsj6tQ51s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQAB
-----END PUBLIC KEY-----
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You store both files in your device and save public one in server which you want to connect, at proper path - that’s it.
If you want to read more about key pair mechanism, &lt;a href=&quot;https://www.ssh.com/ssh/public-key-authentication&quot;&gt;article on ssh.com&lt;/a&gt; explains it nice.&lt;/p&gt;

&lt;h2 id=&quot;how-to-configure-automatic-ssh-connection&quot;&gt;How to configure automatic SSH connection&lt;/h2&gt;
&lt;p&gt;Once you know the theory, it’s time to try automated connection in practice.
First I will show you the process with &lt;em&gt;Seahorse&lt;/em&gt; tool which I find convenient for this task, 
but of course you can achieve the same with command line, which &lt;a href=&quot;#automate-ssh-login-using-command-line&quot;&gt;I will show later&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;em&gt;Ubuntu&lt;/em&gt; and &lt;em&gt;Linux Mint&lt;/em&gt; Seahorse comes pre installed with OS and you can find it as &lt;em&gt;Seahorse&lt;/em&gt; or &lt;em&gt;Passwords and Keys&lt;/em&gt;.
I’m pretty sure it’s not difficult to install it in other distros, so if you don’t have it already, just search how to install it in your case.
It uses &lt;em&gt;libsecret&lt;/em&gt; abstraction which was created to unify access to sensitive data, so it should work on all popular Linux distributions.&lt;/p&gt;

&lt;p&gt;If you don’t see secrets categories on the left side of &lt;em&gt;Seahorse&lt;/em&gt;, set &lt;em&gt;View&lt;/em&gt; » &lt;em&gt;By Keyring&lt;/em&gt;.
&lt;img src=&quot;/assets/images/seahorse-view.jpg&quot; alt=&quot;Screenshot of Seahorse tool with view configuration opened&quot; title=&quot;Seahorse view configuration&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;create-ssh-keys&quot;&gt;Create SSH keys&lt;/h3&gt;
&lt;p&gt;Choose &lt;em&gt;OpenSSH Keys&lt;/em&gt; category and press &lt;em&gt;+&lt;/em&gt; button
&lt;img src=&quot;/assets/images/seahorse-add-ssh-keys.jpg&quot; alt=&quot;Screenshot of Seahorse tool with cursor on add ssh keys button with plus sign&quot; title=&quot;Press add SSH keys button&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Select &lt;em&gt;Secure Shell Key&lt;/em&gt;
&lt;img src=&quot;/assets/images/seahorse-select-ssh.jpg&quot; alt=&quot;Screenshot of Seahorse tool with Secure Shell Key option selected&quot; title=&quot;Select Secure Shell Key option&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now give your keys some description, to remember what is this for.
This name will be seen on server, so you can write here your email address, to simplify server administration
(so maintainer could know who uses this and if it’s still required).&lt;/p&gt;

&lt;p&gt;Choose encryption type - at the time of writing the only available options in Seahorse are &lt;a href=&quot;https://en.wikipedia.org/wiki/RSA_(cryptosystem)&quot;&gt;&lt;em&gt;RSA&lt;/em&gt;&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/Digital_Signature_Algorithm&quot;&gt;&lt;em&gt;DSA&lt;/em&gt;&lt;/a&gt; - 
it’s a bit subjective, but I suggest choosing &lt;em&gt;RSA&lt;/em&gt; as &lt;a href=&quot;https://security.stackexchange.com/questions/5096/rsa-vs-dsa-for-ssh-authentication-keys&quot;&gt;explained on security.stackexchange.com&lt;/a&gt;.
There is a way to choose &lt;a href=&quot;https://ed25519.cr.yp.to/&quot;&gt;&lt;em&gt;Ed25519&lt;/em&gt; algorithm&lt;/a&gt; which is more secure and gives better performance, but currently only &lt;a href=&quot;#automate-ssh-login-using-command-line&quot;&gt;from command line&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;RSA&lt;/em&gt; key strength can be left 2048 bits as is by default. You can increase it, but be aware that some devices may not support it and that it takes a bit more of resources to work with bigger number.
But if you insist, 4096bits should be fine.
Here is nice &lt;a href=&quot;https://danielpocock.com/rsa-key-sizes-2048-or-4096-bits/&quot;&gt;article which explains RSA key size topic&lt;/a&gt; with details.&lt;/p&gt;

&lt;p&gt;From this point you can choose two options:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;Just Create Key&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Create and Set Up&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With second option you will populate newly created key to server right from this wizard, so that’s what we will do.
If you don’t have access to server at this moment, you can just create key and populate it later &lt;a href=&quot;#automate-ssh-login-using-command-line&quot;&gt;from command line&lt;/a&gt;.
&lt;img src=&quot;/assets/images/seahorse-new-secure-shell-key.jpg&quot; alt=&quot;Screenshot of Seahorse tool with new Secure Shell Key configuration&quot; title=&quot;Configure new Secure Shell Key&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;encrypt-ssh-keys-with-password&quot;&gt;Encrypt SSH keys with password&lt;/h3&gt;
&lt;p&gt;Next you will be asked to write passphrase for new secure shell key. It may be a bit confusing - you may wonder if this password must match SSH user password - 
it doesn’t need to, moreover - it shouldn’t - it is different password so it should be different (you won’t need to remember it).
If you leave it blank your private key will be saved on disk unencrypted, which causes security risks. 
Despite some people advice to leave it this way I don’t see any reason not to encrypt it,
that way or another you won’t need to remember it - &lt;a href=&quot;#connect-and-store-encryption-password-in-keyring&quot;&gt;we will use keyring&lt;/a&gt; for that (but it this moment save it somewhere, preferably in some password manager).
Enter strong passphrase, I recommend using some tool which will generate it (I use &lt;a href=&quot;https://keepassxc.org/&quot;&gt;&lt;em&gt;KeepassXC&lt;/em&gt;&lt;/a&gt;), then enter it again as confirmation.
&lt;img src=&quot;/assets/images/seahorse-passphrase.jpg&quot; alt=&quot;Screenshot of Seahorse tool with opened window with passphrase for new secure shell key&quot; title=&quot;Enter good quality password&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;check-created-keys-files&quot;&gt;Check created keys files&lt;/h3&gt;
&lt;p&gt;Now you should have new files in &lt;em&gt;~/.ssh&lt;/em&gt; directory, as &lt;a href=&quot;#how-automate-ssh-connection-works&quot;&gt;described earlier&lt;/a&gt; - &lt;em&gt;id_rsa&lt;/em&gt; with private key and &lt;em&gt;id_rsa.pub&lt;/em&gt; with public key.
If you &lt;a href=&quot;#encrypt-ssh-keys-with-password&quot;&gt;skipped encrypting private key&lt;/a&gt; you will see it in plain text,
otherwise it will be encrypted and will contain header which indicates encryption, for example: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Proc-Type: 4,ENCRYPTED&lt;/code&gt;.
&lt;img src=&quot;/assets/images/ssh-directory.jpg&quot; alt=&quot;Screenshot of ~/.ssh directory with rsa keys&quot; title=&quot;Private and public keys on disk&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;send-public-key-to-server&quot;&gt;Send public key to server&lt;/h3&gt;
&lt;p&gt;If you decided to create key and set it up, you will now see new Window - &lt;em&gt;Set Up Computer for SSH Connection&lt;/em&gt;.
Write your server address and a port in format &lt;em&gt;server:port&lt;/em&gt; then your login name and press &lt;em&gt;Set Up&lt;/em&gt; button. You will be asked for given user password.
&lt;img src=&quot;/assets/images/seahorse-server-address.jpg&quot; alt=&quot;Screenshot of Seahorse tool with server address configuration&quot; title=&quot;Write proper server address with port and user name&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;connect-and-store-encryption-password-in-keyring&quot;&gt;Connect and store encryption password in keyring&lt;/h3&gt;
&lt;p&gt;If setting up succeeds, then in user directory on server will be copy of your public key in &lt;em&gt;~/.ssh&lt;/em&gt; directory in &lt;em&gt;authorized_keys&lt;/em&gt; file - connect to server and check if it is there.
It may look like this:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxGhrhgMsQqOvXf+M1z04toa65/8vY6b+lzjAas7YJqut65o0ONWItpz2UHXSl0mFlbN49UR6VDR9jesUKW+vfuIRUaPs+8/bNEP5tIzPq3lSvw1msYNBT2kbQWO5+Qqiy7EXf/RJ7z4BGiBDEZ4rRhjxIrPAuaxeOpWU6KEDlsxCczxZWgl2xcldhk5oJwzItNd2piQlr7r2CYibHU36XtELvAhlTI1/p11rfSf/BwGtCxb25dApg8k/yRw2zpdV/JD0nfNQiESnCSmLxDr66WK5dScpXQ8zRMRSM3ekoo2ElkDEl9gQ9PhrqdKDLiPqgbobhi22ro4GKsHHAy2VF GitGitRsa
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Do it as usual, just: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh user@server.com -p 22&lt;/code&gt;
To see file you can for example write: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cat ~/.ssh/authorized_keys&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When you try to connect for the first time, you should be asked for password to &lt;em&gt;Unlock private key&lt;/em&gt;.
Set &lt;em&gt;Automatically unlock this key whenever I’m logged in&lt;/em&gt; checkbox and since now it will be unlocked along with your login keyring, when you log in. You will no longer see this window and
your private key will be encrypted - like I told, there is no reason not to encrypt it, it’s secure and convenient at the same time.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/seahorse-unlock-private-key.jpg&quot; alt=&quot;Screenshot of Seahorse window to unlock private key&quot; title=&quot;Unlock private key and set automate unlock checkbox&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;automate-ssh-login-using-command-line&quot;&gt;Automate SSH login using command line&lt;/h2&gt;
&lt;p&gt;In my view if Seahorse works in your case, it’s convenient to use it’s wizard, but there is one exception:
when you want to use &lt;a href=&quot;https://ed25519.cr.yp.to/&quot;&gt;&lt;em&gt;Ed25519&lt;/em&gt; algorithm&lt;/a&gt; which, like I told earlier in this article, 
is more secure and gives better performance, you must use command line, as at the time of writing it’s not supported in Seahorse wizard.&lt;/p&gt;

&lt;p&gt;Bellow steps are exact equivalent of previous from Seahorse tool, just written from command line 😺&lt;/p&gt;

&lt;p&gt;First generate a new &lt;em&gt;Ed25519&lt;/em&gt; SSH key pair (if you haven’t done it already):&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ssh-keygen &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; ed25519 &lt;span class=&quot;nt&quot;&gt;-C&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;description or your email&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If server which you want to reach doesn’t support &lt;em&gt;Ed25519&lt;/em&gt; or if you have old version of &lt;em&gt;OpenSSH&lt;/em&gt; on your PC (&lt;em&gt;Ed25519&lt;/em&gt; was introduced to &lt;em&gt;OpenSSH&lt;/em&gt; in version 6.5), use &lt;em&gt;RSA&lt;/em&gt; instead:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ssh-keygen &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; rsa &lt;span class=&quot;nt&quot;&gt;-b&lt;/span&gt; 2048 &lt;span class=&quot;nt&quot;&gt;-C&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;description or your email&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Description or email is optional, but it’s good to put some convenient information here, because as I &lt;a href=&quot;#create-ssh-keys&quot;&gt;described earlier&lt;/a&gt;, this name will be seen on server, 
so it should identify you, so administrator will know who uses it.&lt;br /&gt;
If you wonder how many bits should have &lt;em&gt;RSA&lt;/em&gt; key size (in above example 2048 bits), it’s the same case which I described during &lt;a href=&quot;#create-ssh-keys&quot;&gt;key creation with Seahorse tool&lt;/a&gt;.
The bigger number you choose, the better security you have, but it comes with a bit bigger resources usage, and with risk, that it will not work - some devices don’t support
length bigger than 2048. I recommend &lt;a href=&quot;https://danielpocock.com/rsa-key-sizes-2048-or-4096-bits/&quot;&gt;good article about RSA key size length&lt;/a&gt;,
for those who want to understand choice better.&lt;/p&gt;

&lt;p&gt;First you will be asked about path where to save keys - use default option by hitting &lt;em&gt;Enter&lt;/em&gt;.
If you’re warned that key already exist, you must choose custom path and later set up &lt;em&gt;~/.ssh/config&lt;/em&gt; file.&lt;/p&gt;

&lt;p&gt;Next you will be asked for encryption password. This is not your SSH user password, so create strong password, different than user’s one, the best option is to generate it with some tool.
You won’t need to remember it, but before you configure everything, save it somewhere - the best option is to use passwords manager - I recommend &lt;a href=&quot;https://keepassxc.org/&quot;&gt;&lt;em&gt;KeepassXC&lt;/em&gt;&lt;/a&gt;.
I described why to do that &lt;a href=&quot;#encrypt-ssh-keys-with-password&quot;&gt;in earlier part of this article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now you can &lt;a href=&quot;#check-created-keys-files&quot;&gt;check created keys files&lt;/a&gt; to ensure everything worked as expected.&lt;/p&gt;

&lt;p&gt;If you had to enter custom path for keys, now you should configure it:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# Only if created keys at custom path &lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;eval&lt;/span&gt; &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;ssh-agent &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;
ssh-add ~/.ssh/YOUR_NEW_PRIVATE_KEY
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And save &lt;em&gt;~/.ssh/config&lt;/em&gt; file as in below example:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# Only if created keys at custom path 
Host gitlab.com
  Preferredauthentications publickey
  IdentityFile ~/.ssh/GITLAB_COM_KEY

Host github.com
  Preferredauthentications publickey
  IdentityFile ~/.ssh/GITHUB_COM_KEY
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next you need to copy your public key to server, this can be done with one command:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ssh-copy-id user@server
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;or if &lt;em&gt;ssh-copy-id&lt;/em&gt; utility is not available on your device, you can use plain &lt;em&gt;ssh&lt;/em&gt; solution&lt;br /&gt;
(change &lt;em&gt;PUBLIC_KEY.pub&lt;/em&gt; to what you have generated, for example &lt;em&gt;id_rsa.pub&lt;/em&gt;):&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; ~/.ssh/PUBLIC_KEY.pub | ssh &amp;lt;user&amp;gt;@&amp;lt;&lt;span class=&quot;nb&quot;&gt;hostname&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;cat &amp;gt;&amp;gt; .ssh/authorized_keys &amp;amp;&amp;amp; echo &quot;Key copied&quot;&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next &lt;a href=&quot;#connect-and-store-encryption-password-in-keyring&quot;&gt;check if public key is copied as expected and store encryption password in keyring&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;troubleshooting-ssh-key-pairing&quot;&gt;Troubleshooting SSH key pairing&lt;/h2&gt;
&lt;p&gt;If automate connection doesn’t work and you don’t know what has failed, and you have only one remote SSH server,
you may want to try everything from scratch - maybe you made some mistake?
That is what helped me, but &lt;strong&gt;use it only if you’re sure you don’t have any other keys already&lt;/strong&gt; and just in case copy files as backup.&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Remove all files from local &lt;em&gt;~/.ssh&lt;/em&gt; directory.&lt;/li&gt;
  &lt;li&gt;Remove all files from remote (server) &lt;em&gt;~/.ssh&lt;/em&gt; directory.&lt;/li&gt;
  &lt;li&gt;Try &lt;a href=&quot;#how-to-configure-automatic-ssh-connection&quot;&gt;setting up everything&lt;/a&gt; again.
I suggest reading &lt;a href=&quot;#how-automate-ssh-connection-works&quot;&gt;short description how key pair automation works&lt;/a&gt;, to know what is happening during process.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you see that keys are generated correctly, but copying to server failed, try to copy it manually (it may require &lt;em&gt;sudo&lt;/em&gt; access):&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Copy public key to server, for example with &lt;em&gt;scp&lt;/em&gt; - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scp ~/.ssh/PUBLIC_KEY.pub user@server:/home/user/PUBLIC_KEY.pub&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Login to server as usual, for example: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh user@server.com -p 22&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Create &lt;em&gt;.ssh&lt;/em&gt; directory, for example with command: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mkdir ~/.ssh&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Append the public key content to &lt;em&gt;authorized_keys&lt;/em&gt; file: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cat ~/PUBLIC_KEY.pub &amp;gt;&amp;gt; ~/.ssh/authorized_keys&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If your key is copied to &lt;em&gt;~/.ssh/authorized_keys&lt;/em&gt; file on server but automate connection doesn’t work, try changing remote user permissions to &lt;em&gt;711&lt;/em&gt;
(some people advice to do it as well for user home directory) - you may need &lt;em&gt;sudo&lt;/em&gt; access:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Login to server as usual, for example: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh user@server.com -p 22&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd ~&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chmod 711 .&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chmod 711 .ssh/&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chmod 711 .ssh/authorized_keys&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chown -R USERANAME .ssh/&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;If you have any questions feel free to ask them in comments, or just to tell if this article has helped you.
If you know someone who also uses SSH protocol to manage remote Git repo, don’t hesitate to send him or her link, 
it may help yet another person and I will be glad too :)&lt;/p&gt;</content>

      
      
      
      
      

      <author>
          <name>Tometchy</name>
        
        
      </author>

      

      
        <category term="linux" />
      
        <category term="git" />
      
        <category term="security" />
      

      
        <summary type="html">If you have to connect to Git via SSH, your usual credential manager may be not enough. Read how to avoid entering password every time on your Linux device.</summary>
      
    </entry>
  
    
    
    
    <entry>
      <title type="html">TFS Linux Agent with error: The user’s home directory could not be determined</title>
      
      <link href="https://www.softwaredeveloper.blog/tfs-linux-agent-dotnet-home-directory-could-not-be-determined" rel="alternate" type="text/html" title="TFS Linux Agent with error: The user&apos;s home directory could not be determined" />
      <published>2019-06-08T06:00:00+00:00</published>
      <updated>2019-06-08T06:00:00+00:00</updated>
      <id>https://www.softwaredeveloper.blog/tfs-linux-agent-dotnet-home-directory-could-not-be-determined</id>
      <content type="html" xml:base="https://www.softwaredeveloper.blog/tfs-linux-agent-dotnet-home-directory-could-not-be-determined">&lt;p&gt;How to fix problem with dotnet restore on TFS 2017 Linux agent - &lt;em&gt;The user’s home directory could not be determined&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I have recently configured Linux agent for Team Foundation Server 2017 to be able to run dotnet core project there.
But during &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet restore&lt;/code&gt; step error was thrown: &lt;em&gt;Error: /usr/bin/dotnet failed with return code: 1&lt;/em&gt; with more explanation:
&lt;em&gt;The user’s home directory could not be determined. Set the ‘DOTNET_CLI_HOME’ environment variable to specify the directory to use.&lt;/em&gt;
It may occur also on newer versions of TFS and on its online version - Visual Studio Team Services (VSTS), currently called Azure DevOps.&lt;/p&gt;

&lt;p&gt;After quick search I knew that dotnet needs to know where home is located for some operations.&lt;/p&gt;

&lt;h3 id=&quot;agent-logs&quot;&gt;Agent logs&lt;/h3&gt;
&lt;p&gt;Full agent logs for dotnet restore step:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-log&quot; data-lang=&quot;log&quot;&gt;[section]Starting: Restore
==============================================================================
Task         : .NET Core
Description  : Build, test and publish using dotnet core command-line.
Version      : 1.0.1
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?linkid=832194)
==============================================================================
[command] /usr/bin/dotnet restore /home/tfs-agent/PS-TFS-AGENT-LNX01_agent01/_work/2/s/ProjectName/ProjectName.csproj
The user&apos;s home directory could not be determined. Set the &apos;DOTNET_CLI_HOME&apos; environment variable to specify the directory to use.
[error] Error: /usr/bin/dotnet failed with return code: 1
[error] Dotnet command failed with non-zero exit code on the following projects : /home/tfs-agent/PS-TFS-AGENT-LNX01_agent01/_work/2/s/ProjectName/ProjectName.csproj
[section] Finishing: Restore&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;what-didnt-help&quot;&gt;What didn’t help&lt;/h3&gt;
&lt;p&gt;First I checked if &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$HOME&lt;/code&gt; variable can be seen on this Linux Machine, logged in as user which is given for TFS.
It was ok. Then I set &lt;em&gt;DOTNET_CLI_HOME&lt;/em&gt; as Linux environment variable, pointing to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$HOME&lt;/code&gt;. It didn’t help.
There were much more solutions to check, looking through the internet, but next one worked for me.&lt;/p&gt;

&lt;h3 id=&quot;solution&quot;&gt;Solution&lt;/h3&gt;
&lt;p&gt;This solutions is not elegant, but it works and in my view is acceptable, and it has one big advantage - it doesn’t require access to Linux Machine ssh.
I set &lt;em&gt;DOTNET_CLI_HOME&lt;/em&gt; as build definition variable, pointing to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/tmp&lt;/code&gt; directory. That’s it, now dotnet restore and build works :)
&lt;img src=&quot;/assets/images/tfs-dotnet-cli-home-variable.png&quot; alt=&quot;TFS 2017 build definition variables screenshot&quot; title=&quot;DOTNET_CLI_HOME as build definition variable&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;I don’t know if this solution will work for everyone, but it takes only 2 clicks to try, so definitely it’s good to start with :)&lt;/p&gt;</content>

      
      
      
      
      

      <author>
          <name>Tometchy</name>
        
        
      </author>

      

      
        <category term="quick-tips" />
      
        <category term="linux" />
      

      
        <summary type="html">How to fix problem with dotnet restore on TFS 2017 Linux agent - The user’s home directory could not be determined.</summary>
      
    </entry>
  
    
    
    
    <entry>
      <title type="html">Libsecret - remember Git credentials in Linux Mint and Ubuntu securely</title>
      
        
         
        <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://www.softwaredeveloper.blog/assets/images/git-key.jpg"/>
        <media>https://www.softwaredeveloper.blog/assets/images/git-key.jpg</media>
        <media><img src="https://www.softwaredeveloper.blog/assets/images/git-key.jpg"/></media>
        <media url="https://www.softwaredeveloper.blog/assets/images/git-key.jpg" />
        <img src="https://www.softwaredeveloper.blog/assets/images/git-key.jpg" />
        <image>
          <url>https://www.softwaredeveloper.blog/assets/images/git-key.jpg</url>
          <title>Libsecret - remember Git credentials in Linux Mint and Ubuntu securely</title>
          <link>https://www.softwaredeveloper.blog/git-credential-storage-libsecret</link>
        </image>
      
      <link href="https://www.softwaredeveloper.blog/git-credential-storage-libsecret" rel="alternate" type="text/html" title="Libsecret - remember Git credentials in Linux Mint and Ubuntu securely" />
      <published>2019-03-06T06:00:00+00:00</published>
      <updated>2019-10-29T06:00:00+00:00</updated>
      <id>https://www.softwaredeveloper.blog/git-credential-storage-libsecret</id>
      <content type="html" xml:base="https://www.softwaredeveloper.blog/git-credential-storage-libsecret">&lt;p&gt;Typing username and password every push is burdensome and irritating… libsecret git credential storage to the rescue.&lt;/p&gt;

&lt;p&gt;When you want to use external git repository hosting service, like &lt;em&gt;Gitlab&lt;/em&gt; or &lt;em&gt;GitHub&lt;/em&gt; you need to authorise yourself.
Git has built in credential helper mechanism, which allows choosing the way you have credentials persisted.
It gives you two options out of the box, but you’re not limited to them - you can install third party solution.&lt;/p&gt;

&lt;h3 id=&quot;cache-credential-helper-out-of-the-box&quot;&gt;&lt;em&gt;Cache&lt;/em&gt; credential helper (out of the box)&lt;/h3&gt;
&lt;p&gt;Cache is quite secure because keeps data only in memory. It’s fine for security, but every time you open new session, you need to type credentials again.
Memory is purged after 900 seconds (15 min) by default, but it can be changed with optional &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;timeout&lt;/code&gt; parameter.&lt;/p&gt;

&lt;p&gt;If for some reason you don’t want to install anything, at least use cache :)&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;git config &lt;span class=&quot;nt&quot;&gt;--global&lt;/span&gt; credential.helper &lt;span class=&quot;s1&quot;&gt;&apos;cache --timeout=300&apos;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Official description - &lt;a href=&quot;https://git-scm.com/docs/git-credential-cache&quot;&gt;git-scm.com/docs/git-credential-cache&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;store-credential-helper-out-of-the-box&quot;&gt;&lt;em&gt;Store&lt;/em&gt; credential helper (out of the box)&lt;/h3&gt;
&lt;p&gt;Store keeps your username and password in… plain text file! It’s totally insecure and use it only if you don’t care about your account (for example during some kind of workshops).&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;git config &lt;span class=&quot;nt&quot;&gt;--global&lt;/span&gt; credential.helper store&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Official description - &lt;a href=&quot;https://git-scm.com/docs/git-credential-store&quot;&gt;git-scm.com/docs/git-credential-store&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;git-credential-manager-for-mac-and-linux-by-microsoft&quot;&gt;&lt;em&gt;Git Credential Manager for Mac and Linux&lt;/em&gt; (by Microsoft)&lt;/h3&gt;
&lt;p&gt;Windows users are familiar with convenient &lt;em&gt;Git Credential Manager for Windows&lt;/em&gt; which is integrated with OS way of storing credentials. It can be installed with official wizard or during git installation on Windows (there is checkbox to select).
And recently Microsoft announced release of… &lt;em&gt;Git Credential Manager for Mac and Linux&lt;/em&gt;. I was positively surprised, till I tried to use it on my &lt;em&gt;Linux Mint 19 Tara&lt;/em&gt;. Installation was successful (but not without complications) and attempt to use it ended up with error:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;Fatal: java.lang.RuntimeException encountered. Details: 
Secure credential storage is not available on this operating system. You may opt-in to store credentials &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;an unencrypted file under your user home directory by running &lt;span class=&quot;s1&quot;&gt;&apos;git config --global credential.canFallBackToInsecureStore true&apos;&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt;
fatal: credential helper &lt;span class=&quot;s1&quot;&gt;&apos;!/usr/lib/jvm/java-11-openjdk-amd64/bin/java -Ddebug=false -Djava.net.useSystemProxies=true -jar /home/linuxbrew/.linuxbrew/Cellar/git-credential-manager/2.0.4/libexec/git-credential-manager-2.0.4.jar&apos;&lt;/span&gt; told us to quit&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;I have opened the issue and till now I haven’t received any response (more than 2 months) and recently I have seen the same issue created for &lt;em&gt;Ubuntu 18.04&lt;/em&gt;. So currently it doesn’t work on Linux Mint and Ubuntu.&lt;/p&gt;

&lt;p&gt;Official description - &lt;a href=&quot;https://github.com/Microsoft/Git-Credential-Manager-for-Mac-and-Linux&quot;&gt;github.com/Microsoft/Git-Credential-Manager-for-Mac-and-Linux&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;libsecret-git-credential-storage-by-gnome&quot;&gt;&lt;em&gt;Libsecret&lt;/em&gt; git credential storage (by GNOME)&lt;/h2&gt;
&lt;p&gt;The best way to store Git credentials on Linux used to be &lt;em&gt;GNOME Keyring&lt;/em&gt; (libgnome-keyring), but as it is specific to GNOME, &lt;a href=&quot;https://mail.gnome.org/archives/commits-list/2014-January/msg01585.html&quot;&gt;it is deprecated since January 2014&lt;/a&gt;.
For Git versions 2.11+ you should use credential helper based on &lt;em&gt;libsecret&lt;/em&gt;.
Installation and configuration takes only 4 bash commands :)&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;libsecret-1-0 libsecret-1-dev
&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; /usr/share/doc/git/contrib/credential/libsecret
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;make
git config &lt;span class=&quot;nt&quot;&gt;--global&lt;/span&gt; credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;That’s all, next time when you’ll be asked for your username and password will be the last time on this device :)&lt;/p&gt;

&lt;p&gt;Official description - &lt;a href=&quot;https://wiki.gnome.org/Projects/Libsecret&quot;&gt;wiki.gnome.org/Projects/Libsecret&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;how-to-secure-ssh-credentials&quot;&gt;How to secure SSH credentials&lt;/h2&gt;
&lt;p&gt;Above credential managers work only if you use http(s), which is usual case. If you have to use SSH protocol,
I have described how to skip asking for credentials with SSH key-pair in safe manner, in &lt;a href=&quot;https://www.softwaredeveloper.blog/store-git-ssh-credentials-in-linux&quot;&gt;another article&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;As you see it’s not difficult to protect your credentials and not have to type them all the time.
If it doesn’t work for you or you have some question or unusual case, feel free to ask me in comments, I will do my best to help you.&lt;br /&gt;
If you know someone who uses unsafe credential manager or doesn’t use manager at all, send him this article, I will appreciate it :)&lt;/p&gt;</content>

      
      
      
      
      

      <author>
          <name>Tometchy</name>
        
        
      </author>

      

      
        <category term="linux" />
      
        <category term="git" />
      
        <category term="security" />
      

      
        <summary type="html">Typing username and password every push is burdensome and irritating… libsecret git credential storage to the rescue.</summary>
      
    </entry>
  
</feed>
