{"id":170,"date":"2022-04-26T22:54:00","date_gmt":"2022-04-26T20:54:00","guid":{"rendered":"https:\/\/bowfinger.de\/blog\/?p=170"},"modified":"2022-04-26T21:20:25","modified_gmt":"2022-04-26T19:20:25","slug":"lost-gitea-local-admin-password","status":"publish","type":"post","link":"https:\/\/bowfinger.de\/blog\/2022\/04\/lost-gitea-local-admin-password\/","title":{"rendered":"Lost Gitea Local Admin Password?"},"content":{"rendered":"\n<p>There are various possible ways you can lose access to your Gitea instance. In particular, if you are getting user accounts via LDAP, you should always have a key to get back in: a &#8220;local&#8221; admin.<\/p>\n\n\n\n<p>In case you haven&#8217;t got one (totally not like I did definitely only once \ud83e\udd2b), deleted it or lost its password, here&#8217;s the procedure in to variants: running on plain Linux, and running within Docker.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"plain-linux\">Plain Linux<\/h2>\n\n\n\n<p>List the available (local) user accounts (you may need to run this with <code>sudo<\/code>):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ gitea admin user list\n\nID   Username     Email             IsActive IsAdmin\n1    user1        &#x6d;&#101;&#64;h&#x6f;&#x6d;&#101;&#46;&#x65;&#x61;&#114;t&#x68;     true     false<\/code><\/pre>\n\n\n\n<p>You may not get a single user listed here. In order to add a local administrator, do this<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo gitea admin user create --username local_admin --email &#x61;&#x64;&#109;i&#x6e;&#x73;&#64;em&#x61;&#x69;&#108;&#46;&#x65;&#x61;&#114;&#116;h --admin --random-password\n\ngenerated random password is 'IzgvOwv1M9EG'\nNew user 'local_admin' has been successfully created!\n\n$ sudo gitea admin user list\n\nID   Username     Email                 IsActive IsAdmin\n1    unpriv_local &#x62;o&#x77;f&#x69;&#110;&#x67;&#101;r&#x6d;a&#x69;&#108;&#x40;&#103;&#x6d;&#120;&#46;&#x6e;e&#x74; true     true\n3    local_admin  a&#100;&#109;&#x69;&#x6e;&#x73;&#64;e&#109;&#97;&#x69;&#x6c;&#x2e;e&#97;&#114;&#116;&#x68;    true     true<\/code><\/pre>\n\n\n\n<p>Especially on shared machines, I&#8217;d strongly recommend not setting a password via the command line. It&#8217;ll stick in <code>bash_history<\/code> and may be visible in the process list. Hence the <code>--random-password<\/code> option here. Use the generated password upon first login in the browser.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"docker-container\">Docker Container<\/h2>\n\n\n\n<p>In order to get to the &#8220;plain Linux&#8221; field, you simply run a <code>bash<\/code> in the Gitea Docker container.<\/p>\n\n\n\n<p>What&#8217;s the container&#8217;s name? Get it via <code>docker container ls -a<\/code>. Let&#8217;s say it&#8217;s called <code>gitea<\/code>. To start bash in that container, do<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">user1@linux:$ docker exec -it gitea \/bin\/bash<\/code><\/pre>\n\n\n\n<p>Now, you basically do the same thing as in the section above.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">docker # gitea admin user list\n\nID   Username     Email             IsActive IsAdmin\n1    user1        me&#64;home&#46;eart&#104;     true     false\n\ndocker # gitea admin user create --username local_admin --email &#97;&#100;&#x6d;i&#110;&#x73;&#x40;e&#109;&#x61;&#x69;l&#46;&#x65;a&#114;&#x74;&#x68; --admin --random-password\n\ngenerated random password is 'ikV6xzPTiH7B'\nNew user 'local_admin' has been successfully created!\n\ndocker # gitea admin user list\n\nID   Username     Email                 IsActive IsAdmin\n1    unpriv_local &#x62;&#111;w&#x66;&#105;&#110;&#x67;&#x65;&#114;m&#x61;&#105;l&#x40;&#x67;&#109;x&#x2e;&#110;e&#x74; true     true\n3    local_admin  &#97;&#x64;&#x6d;i&#110;&#x73;&#64;&#101;&#x6d;&#x61;&#105;&#x6c;&#x2e;e&#97;&#x72;t&#104;    true     true<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion (and Other Platforms)<\/h2>\n\n\n\n<p>The Plain Linux approach works equally well on other platforms. I hope this helps.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are various possible ways you can lose access to your Gitea instance. In particular, if you are getting user accounts via LDAP, you should always have a key to get back in: a &#8220;local&#8221; admin. In case you haven&#8217;t got one (totally not like I did definitely only once \ud83e\udd2b), deleted it or lost&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[16,1],"tags":[34,33,32,18],"class_list":["post-170","post","type-post","status-publish","format-standard","hentry","category-linux","category-uncategorized","tag-admin","tag-docker","tag-gitea","tag-linux"],"_links":{"self":[{"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/posts\/170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/comments?post=170"}],"version-history":[{"count":8,"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/posts\/170\/revisions"}],"predecessor-version":[{"id":232,"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/posts\/170\/revisions\/232"}],"wp:attachment":[{"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/media?parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/categories?post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/tags?post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}