{"id":12093,"date":"2022-05-10T10:00:00","date_gmt":"2022-05-10T01:00:00","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=12093"},"modified":"2022-05-10T10:28:36","modified_gmt":"2022-05-10T01:28:36","slug":"encrypt-and-decrypt-files-with-gpg-in-linux","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/12093","title":{"rendered":"Encrypt and Decrypt files with GPG in linux"},"content":{"rendered":"\n<p>Today, I would like to share about encrypting and decrypting files with GPG in linux. Let\u2019s take a look.<\/p>\n\n\n\n<p>GPG, known as GNU Privacy Guard (GnuPG), is an open-source command-line tool to encrypt things like files, emails, messages and so on.<\/p>\n\n\n\n<h3><strong>Installation<\/strong><\/h3>\n\n\n\n<p>GPG usually pre-installed with most of the Linux Distributions. But just in case, you can install by the following command in terminal.<\/p>\n\n\n\n<p>sudo apt install gnupg<\/p>\n\n\n\n<h3><strong>Usage<\/strong><\/h3>\n\n\n\n<p><strong>Generate keys<\/strong><\/p>\n\n\n\n<p>To encrypt files, you need to generate a GPG key on the system firstly.<\/p>\n\n\n\n<p>gpg \u2013full-generate-key<\/p>\n\n\n\n<p>If the options to select are asked, you can read and use default values by pressing Enter.<\/p>\n\n\n\n<p>But you will need to fill name and email.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1308\" height=\"996\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2022\/05\/today1.png\" alt=\"\" class=\"wp-image-12095\" \/><\/figure>\n\n\n\n<p><strong>Checking GPG keys<\/strong><\/p>\n\n\n\n<p>You can also check your key lists as follows.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"678\" height=\"332\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2022\/05\/todayb.png\" alt=\"\" class=\"wp-image-12097\" \/><\/figure>\n\n\n\n<p><strong>Encrypting a file<\/strong><\/p>\n\n\n\n<p>Firstly, let\u2019s create a sample text file with some text.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"792\" height=\"125\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2022\/05\/today4.png\" alt=\"\" class=\"wp-image-12098\" \/><\/figure>\n\n\n\n<p>And let\u2019s encrypt a file by the following command.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1212\" height=\"94\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2022\/05\/today5.png\" alt=\"\" class=\"wp-image-12099\" \/><\/figure>\n\n\n\n<p>The recipient argument is the email you wrote when creating key.<\/p>\n\n\n\n<p>The above command output the encrypted file with .gpg extension. You can delete original file after encryption.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"559\" height=\"85\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2022\/05\/today6.png\" alt=\"\" class=\"wp-image-12101\" \/><\/figure>\n\n\n\n<p>And we can see the contents of the encrypted file as follow.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1207\" height=\"150\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2022\/05\/today7.png\" alt=\"\" class=\"wp-image-12100\" \/><\/figure>\n\n\n\n<p><strong>Decrypting a file<\/strong><\/p>\n\n\n\n<p>You can decrypt an encrypted gpg file by the following command.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1023\" height=\"175\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2022\/05\/today8.png\" alt=\"\" class=\"wp-image-12102\" \/><\/figure>\n\n\n\n<p>This command outputs a decrypted file named decrypted_test.txt. Now you can see correct text contents of the file.<\/p>\n\n\n\n<p>So this is all for now and for more details, I recommend to read <a href=\"https:\/\/gnupg.org\/gph\/en\/manual.html\" data-type=\"URL\" data-id=\"https:\/\/gnupg.org\/gph\/en\/manual.html\">here<\/a>.<\/p>\n\n\n\n<p>Hope you enjoy that.<\/p>\n\n\n\n<p>By Asahi<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12093\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/12093\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"Encrypt and Decrypt files with GPG in linux\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12093\" data-text=\"Encrypt and Decrypt files with GPG in linux\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12093\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12093\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>Today, I would like to share about encrypting and decrypting files with GPG in linux. Let\u2019s take a look. GPG,  [&hellip;]<\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[90,100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/12093"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=12093"}],"version-history":[{"count":5,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/12093\/revisions"}],"predecessor-version":[{"id":12540,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/12093\/revisions\/12540"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=12093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=12093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=12093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}