{"id":39944,"date":"2022-01-02T15:52:27","date_gmt":"2022-01-02T15:52:27","guid":{"rendered":"https:\/\/linuxiac.com\/?p=39944"},"modified":"2022-04-20T18:23:02","modified_gmt":"2022-04-20T18:23:02","slug":"make-sudo-remember-password-longer","status":"publish","type":"post","link":"https:\/\/linuxiac.com\/make-sudo-remember-password-longer\/","title":{"rendered":"How to Make sudo Remember the Password for Longer"},"content":{"rendered":"\n<p>Probably you execute quite a lot of&nbsp;<code>sudo<\/code>&nbsp;commands because you don&#8217;t want to&nbsp;<code>sudo su<\/code>&nbsp;and execute commands as root all the time. However, it can be not very pleasant having to keep entering the <code>sudo<\/code> password. So here&#8217;s how you can deal with it.<\/p>\n\n\n\n<p>You noticed that if you execute one and then another one within a few minutes, the 2nd time, you don&#8217;t get the message like: [sudo] password for your_username. However, you get it when there is more time between the execution of the two commands.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-can-i-make-sudo-last-longer\">How Can I Make sudo Last Longer?<\/h2>\n\n\n\n<p>The behavior of <code>sudo<\/code> is configured in the &#8220;<strong><em>\/etc\/sudoers<\/em><\/strong>&#8221; file, and <strong>by default timeout of the <code>sudo<\/code> command is 15 minutes<\/strong>.<\/p>\n\n\n\n<p>The &#8220;<em>\/etc\/sudoers<\/em>&#8221; file has a <code><strong>timestamp_timeout<\/strong><\/code> option responsible for reprompting the <a href=\"https:\/\/linuxiac.com\/how-to-change-remove-disable-user-password-in-linux\/\">user for a password<\/a> after a specific amount of time.<\/p>\n\n\n\n<p>The good news is that you can increase this number to a larger one (in minutes) by adding a string in the &#8220;<em>\/etc\/sudoers<\/em>&#8221; file. After that time, <code>sudo<\/code> will ask for a password again.<\/p>\n\n\n\n<p>The <code>sudo<\/code> command doesn&#8217;t remember your password, but when you first authorize it, a session is created which lasts for <code>timestamp_timeout<\/code>. It <a href=\"https:\/\/www.sudo.ws\/docs\/man\/sudoers_timestamp.man\/\" target=\"_blank\" rel=\"noreferrer noopener\">stores timestamp<\/a> under the &#8220;<em>\/var\/run\/sudo\/ts\/<\/em>&#8221; directory.<\/p>\n\n\n\n<p>It&#8217;s essential to make sure you edit your <code>sudoers<\/code> file using <code>visudo<\/code>, which checks your syntax and will not leave you with the wrong configuration and inaccessible <code>sudo<\/code>.<\/p>\n\n\n\n<p>In other words, running <code>sudo visudo<\/code> instead of editing the file directly causes the system to validate the &#8220;<em>\/etc\/sudoers<\/em>&#8221; file before it commits the changes.<\/p>\n\n\n\n<p>To make the <code>sudo<\/code> command last longer, run the following command in terminal:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">sudo visudo<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Find the lines starting with &#8220;<em>Defaults<\/em>&#8221; and add &#8220;<em>Defaults timestamp_timeout=x<\/em>&#8221; where &#8220;<em>x<\/em>&#8221; is the number of minutes you want between reprompts. In our case, we set this value to 60.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2022\/01\/sudo-remember-password-2.png\"><img decoding=\"async\" width=\"1024\" height=\"642\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2022\/01\/sudo-remember-password-2-1024x642.png\" alt=\"Make sudo Remember the Password for Longer\" class=\"wp-image-39950\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2022\/01\/sudo-remember-password-2-1024x642.png 1024w, https:\/\/linuxiac.com\/wp-content\/uploads\/2022\/01\/sudo-remember-password-2-360x226.png 360w, https:\/\/linuxiac.com\/wp-content\/uploads\/2022\/01\/sudo-remember-password-2-768x481.png 768w, https:\/\/linuxiac.com\/wp-content\/uploads\/2022\/01\/sudo-remember-password-2-480x301.png 480w, https:\/\/linuxiac.com\/wp-content\/uploads\/2022\/01\/sudo-remember-password-2.png 1174w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>That&#8217;s it. Save the file and exit. The <code>sudo<\/code> password prompt will time out after an hour&nbsp;(60&nbsp;minutes) once <code>sudo<\/code> is invoked by a user.<\/p>\n\n\n\n<p>In addition, if you specify <code>0<\/code>, you will always be asked for the password. Keep in mind that if you set a negative value, for example, <code>-1<\/code>, the timeout will never expire.<\/p>\n\n\n\n<p>Of course, <strong>specifying a negative value is not recommended<\/strong> and should be treated as a <strong>bad security practice<\/strong>.<\/p>\n\n\n\n<p>Please find out more about various options in\u00a0sudoers\u00a0on its command line\u00a0<a href=\"https:\/\/linux.die.net\/man\/5\/sudoers\" target=\"_blank\" rel=\"noreferrer noopener\">manual page<\/a>.<\/p>\n\n\n\n<p>If you have any questions or feedback, feel free to leave a comment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here\u2019s how to make sudo remember your password for longer so that you don\u2019t have to keep typing it repeatedly.<\/p>\n","protected":false},"author":10,"featured_media":39947,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,4417],"tags":[4520,4526,4523],"class_list":["post-39944","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips","category-linux-knowledge","tag-sudo","tag-sudo-timeout","tag-sudoers"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6},"post_title_panel":"","has_hero_section":"default","77e56c34fdcaa8da5e7b984d3fbf62eb":"","hero_section":"type-2","hero_elements":[{"id":"custom_title","enabled":true,"heading_tag":"h1","title":"Home","__id":"f_fzll5CDnE8NXVZzfGD4"},{"id":"custom_description","enabled":false,"description_visibility":{"desktop":true,"tablet":true,"mobile":false},"__id":"m2NI7OR42hZw0TIGxoGaC"},{"id":"custom_meta","enabled":true,"meta_elements":[{"id":"author","enabled":true,"label":"By","has_author_avatar":"yes","avatar_size":50,"__id":"r0p1KRVmfm_rcwHNdwFXU"},{"id":"post_date","enabled":false,"label":"On","date_format_source":"default","date_format":"M j, Y","__id":"oRi_ZbH5oz7xxLi-rBC52"},{"id":"updated_date","enabled":true,"label":"Updated","date_format_source":"default","date_format":"M j, Y","__id":"2GVxSHZ-TOsckG-o_J3-f"},{"id":"categories","enabled":false,"label":"In","style":"simple","__id":"Efz_lRfBwxKOI1e-YOn8V"},{"id":"comments","enabled":true,"__id":"bcrljHsGPeLtNhBaVSfzy"}],"page_meta_elements":{"joined":true,"articles_count":true,"comments":true},"__id":"K9u_iP49pLCGsxLK-N8RE","meta_type":"label","meta_divider":"circle"},{"id":"breadcrumbs","enabled":false,"__id":"c3kQgFGZbJjQRIrk3hRug"}],"9c8ce6a65d1fd2a7ddddddb5bace0249":"","hero_alignment1":"CT_CSS_SKIP_RULE","hero_margin":40,"hero_alignment2":"center","hero_vertical_alignment":"center","f2f238ece32086e91c767212da8e1984":"","hero_structure":"normal","608ea6226d9114ad4f4196074e35cdae":"","page_title_bg_type":"custom_image","custom_hero_background":{"attachment_id":43316,"url":"https:\/\/linuxiac.com\/wp-content\/uploads\/2022\/01\/sudo-remember-password-header-1024x226.png"},"parallax":{"desktop":false,"tablet":false,"mobile":false},"6c537fe15eaf60eafb80e4f7974072bf":"","hero_height":"250px","pageTitleFont":{"family":"Default","variation":"Default","size":{"desktop":"2.8em","tablet":"2.8em","mobile":"2.8em","__changed":[]},"line-height":"CT_CSS_SKIP_RULE","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"CT_CSS_SKIP_RULE","text-decoration":"CT_CSS_SKIP_RULE"},"pageTitleFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageMetaFont":{"family":"Default","variation":"n6","size":"12px","line-height":"1.3","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"uppercase","text-decoration":"CT_CSS_SKIP_RULE"},"pageMetaFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"page_meta_button_type_font_colors":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"page_meta_button_type_background_colors":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageExcerptFont":{"family":"Default","variation":"Default","size":"CT_CSS_SKIP_RULE","line-height":"CT_CSS_SKIP_RULE","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"CT_CSS_SKIP_RULE","text-decoration":"CT_CSS_SKIP_RULE"},"pageExcerptColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"breadcrumbsFont":{"family":"Default","variation":"Default","size":"CT_CSS_SKIP_RULE","line-height":"CT_CSS_SKIP_RULE","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"CT_CSS_SKIP_RULE","text-decoration":"CT_CSS_SKIP_RULE"},"breadcrumbsFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"initial":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageTitleOverlay":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"CT_CSS_SKIP_RULE"}}},"pageTitleBackground":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"var(--theme-palette-color-6)"}}},"pageTitlePadding":{"top":"50px","bottom":"50px","left":"auto","right":"auto","linked":true},"83ca24ec6f9cb3f3cebbaad58176271f":"","page_structure_type":"default","effd16e0e536fc3825ab4f81ae938d45":"","content_style_source":"inherit","content_style":"wide","5baa1ed8ddb7bb64ae2f5fd7e2fa16a6":"","vertical_spacing_source":"inherit","content_area_spacing":"both","background":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"CT_CSS_SKIP_RULE"}}},"content_background":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"var(--theme-palette-color-8)"}}},"content_boxed_shadow":{"inherit":false,"blur":18,"spread":-6,"v_offset":12,"h_offset":0,"inset":false,"enable":true,"color":{"color":"rgba(34, 56, 101, 0.04)"}},"boxed_content_spacing":{"desktop":{"top":"40px","bottom":"40px","left":"40px","right":"40px","linked":true},"tablet":{"top":"35px","bottom":"35px","left":"35px","right":"35px","linked":true},"mobile":{"top":"20px","bottom":"20px","left":"20px","right":"20px","linked":true}},"content_boxed_radius":{"top":"3px","bottom":"3px","left":"3px","right":"3px","linked":true},"4c3d9f601a1b76a60a49d8b0f48399f4":"","disable_featured_image":"no","disable_post_tags":"no","disable_share_box":"no","disable_author_box":"no","disable_posts_navigation":"no","disable_subscribe_form":"no","3191711bd4ebc84aef2d298d7e798ce8":"","disable_related_posts":"no","disable_header":"no","disable_footer":"no","c6f83ed29890f512413812ffc77c2464":"","header_footer_scripts_panel":"","header_scripts":"","e8ddf2c186e7f2bc9bb2950d7c121204":"","header_after_body_scripts":"","266f6995d289d104da8a513278454cd9":"","footer_scripts":""},"_links":{"self":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts\/39944","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/comments?post=39944"}],"version-history":[{"count":0,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts\/39944\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/media\/39947"}],"wp:attachment":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/media?parent=39944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/categories?post=39944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/tags?post=39944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}