<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Luiz Carlos Cosmi Filho</title>
    <description>The latest articles on DEV Community by Luiz Carlos Cosmi Filho (@luizcarloscf).</description>
    <link>https://dev.to/luizcarloscf</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F454250%2F38905db6-8cb5-4e3b-891e-df55bb8f87c8.jpeg</url>
      <title>DEV Community: Luiz Carlos Cosmi Filho</title>
      <link>https://dev.to/luizcarloscf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/luizcarloscf"/>
    <language>en</language>
    <item>
      <title>Store personal access token of Github</title>
      <dc:creator>Luiz Carlos Cosmi Filho</dc:creator>
      <pubDate>Tue, 24 Aug 2021 15:29:21 +0000</pubDate>
      <link>https://dev.to/luizcarloscf/store-personal-access-token-of-github-131b</link>
      <guid>https://dev.to/luizcarloscf/store-personal-access-token-of-github-131b</guid>
      <description>&lt;p&gt;First, it is important to get used to generate Personal Access Token (PAT). On Github, you can follow the tutorial of &lt;a href="https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token"&gt;Creating a personal access token&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Although it seems to, a token is not a simple password. You can generate multiple tokens (e.g. one per machine) or revoke acces any time you want. So, that makes easy for us to manage access in our Github account.&lt;/p&gt;

&lt;p&gt;As highlighted by github in &lt;a href="https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token"&gt;Creating a personal access token&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Once you have a token, you can enter it instead of your password when performing Git operations over HTTPS.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, it is possible to use it instead of your password when cloning a private repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git clone https://github.com/username/private-repo.git
Username: your_username
Password: your_token
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Github recommends you use Git Credential Manager Core (GCM Core) to remember your credentials.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Instead of manually entering your PAT for every HTTPS Git operation, you can cache your PAT with a Git client. Git will temporarily store your credentials in memory until an expiry interval has passed. You can also store the token in a plain text file that Git can read before every request.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The installations instructions can be found in the github &lt;a href="https://github.com/microsoft/Git-Credential-Manager-Core#download-and-install"&gt;README.md&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are several methods for storing credentials that GCM Core manages on Linux platforms. In the documentation of &lt;a href="https://github.com/microsoft/Git-Credential-Manager-Core/blob/main/docs/linuxcredstores.md#credential-stores-on-linux"&gt;Credential stores on Linux&lt;/a&gt;, you can found all available methods.&lt;/p&gt;

&lt;p&gt;We could choose plaintext, but this credential store saves credentials to plaintext files in your file system. It isn't a secure method, once the PAT remains expose in your host.&lt;/p&gt;

&lt;p&gt;Instead, use &lt;code&gt;libsecret&lt;/code&gt;. If it's not already pre-installed on your machine, use the following procedure:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make sure &lt;code&gt;libsecret&lt;/code&gt; is installed:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;libsecret-1-0 libsecret-1-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Then build the credential helper from the sources shipped with libsecret's development libraries:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;make &lt;span class="nt"&gt;--directory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/share/doc/git/contrib/credential/libsecret
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Finally, register the freshly compiled binary as a Git credential helper:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; credential.helper &lt;span class="se"&gt;\&lt;/span&gt;
   /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, if you download a private repository and put your PAT instead of your password, git will store it securely on your computer.&lt;/p&gt;

&lt;p&gt;GCM Core highlights that, &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It stores credentials securely in 'collections', which can be viewed by tools such as secret-tool and seahorse. A graphical user interface is required in order to show a secure prompt to request a secret collection be unlocked.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, to view your PAT you can use &lt;code&gt;secret-tool&lt;/code&gt; following the procedure:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make sure &lt;code&gt;secret-tools&lt;/code&gt; is installed:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;libsecret-tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;secret-tool&lt;/code&gt; stores credentials based on key/value pairs. So, you can show your PAT looking for credential
associated with github.com server.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;secret-tool lookup server github.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I hope you found this article helpful. If you need any help please let me know in the comment section.&lt;/p&gt;

&lt;p&gt;Let's connect on &lt;a href="https://github.com/luizcarloscf"&gt;GitHub&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/luizcarloscf/"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;👋 Thanks for reading, see you next time.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;This article is a compilation made from different source materials cited below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/microsoft/Git-Credential-Manager-Core"&gt;https://github.com/microsoft/Git-Credential-Manager-Core&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token"&gt;https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git"&gt;https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
