{"id":89,"date":"2018-12-16T03:49:00","date_gmt":"2018-12-15T22:19:00","guid":{"rendered":"https:\/\/memoirs.vu2aie.in\/?p=89"},"modified":"2020-09-13T04:00:43","modified_gmt":"2020-09-12T22:30:43","slug":"secure-your-raspberry-pi-first-step-renaming-pi-user","status":"publish","type":"post","link":"https:\/\/memoirs.vu2aie.in\/?p=89","title":{"rendered":"Secure your Raspberry PI: First step Renaming &#8216;pi&#8217; user."},"content":{"rendered":"\n<p>Half of the hackers work is already done when he knows the user neame of te target. This flaw is present in most of the entry level routers, and cannot be changed. Raspberry OS (Raspbian) ships with the default user PI, this user name has to be changed if we want to secure out Pi over the network.<\/p>\n\n\n\n<p><strong>Why should I be bothered?<\/strong><\/p>\n\n\n\n<p>I had put my &#8216;PI&#8217; on the DMZ behind the router to make it as a gateway to access my home assistant from the web. Over a week there were more than a thousand failed login attempt in my log, most common attempted user after &#8216;root&#8217; &amp; &#8216;admin&#8217;  was &#8216;pi&#8217;<\/p>\n\n\n\n<p>This was sufficient to motivate me to change the default username &#8216;pi&#8217;.<\/p>\n\n\n\n<p><strong>What is the big deal? create a new user and delete the default user!<\/strong><\/p>\n\n\n\n<p>That&#8217;s correct! Essentially I am doing that but without deleting or creating a user. Remember, with each user there are certain permissions (sudo) and groups that the user is member of. Creating a new user and adding multiple groups is going to take a long time and then it may cause issue in some of the default scripts (booting to the user pi) and needs many scripts to be revisited.<\/p>\n\n\n\n<p class=\"has-large-font-size\"><strong>The easy way!<\/strong><\/p>\n\n\n\n<p>Changing the default user is much simpler with the following steps<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container\">\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container\">\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container\">\n<ul><li>enable &#8216;root&#8217; user<\/li><li>enable &#8216;root&#8217; user login through SSH<\/li><li>login as &#8216;root&#8217;<\/li><li>change the user &#8216;pi&#8217; to &#8216;new_user&#8217;<\/li><li>change the user $HOME directory<\/li><li>disable &#8216;root&#8217; SSH login and user &#8216;root&#8217;<\/li><li>reboot, if you like<\/li><\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Steps to change the username<\/strong><\/p>\n<\/div><\/div>\n\n\n\n<p class=\"has-medium-font-size\"><strong>First enable the root user:<\/strong><\/p>\n\n\n\n<p>In most of the Debian derived OS the root user is disabled by default. To enable it we need to set the root password using <\/p>\n\n\n\n<p class=\"has-text-align-left\">sudo passwd root<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container\">\n<p>The system will ask for the new password and confirm the new password. <\/p>\n\n\n\n<p>Nothing will be printed on the screen while typing the password.<\/p>\n<\/div><\/div>\n\n\n\n<p><strong>Enable root login through SSH<\/strong><\/p>\n\n\n\n<p>&#8216;root&#8217; login can be enabled by editing the sshd config file, I use nano as the editor.<\/p>\n\n\n\n<p><em><strong>sudo nano \/etc\/ssh\/sshd_config<\/strong><\/em><\/p>\n<\/div><\/div>\n\n\n\n<p>In the file find  <strong>&#8221;PermitRootLogin no&#8217; <\/strong>and replace it with &#8216;<strong>&#8216;PermitRootLogin yes&#8217;<\/strong><\/p>\n\n\n\n<p>Reboot or restart sshd using <\/p>\n\n\n\n<p><em><strong>&#8216;sudo systemctl restart ssh&#8217;<\/strong><\/em><\/p>\n<\/div><\/div>\n\n\n\n<p>login as root with the password created above and rename the user &#8216;pi&#8217; to &#8216;new_user_name&#8217;,  using the command (replace new_user with the desired user name)<\/p>\n\n\n\n<p><em><strong>usermod -l new_user_name pi<\/strong><\/em><\/p>\n\n\n\n<p>Once the user is renamed we need to change the user&#8217;s home directory name to reflect the new login name. This can be done using the following command<\/p>\n\n\n\n<p><em><strong>usermod -m -d \/home\/new_user_name new_user_name<\/strong><\/em><\/p>\n\n\n\n<p>check the \/home directory for the new user name and permission using<\/p>\n\n\n\n<p><strong><em>ls -l \/home<\/em><\/strong><\/p>\n\n\n\n<p>Finally, we need to modify the group of the new user using the command<\/p>\n\n\n\n<p><strong><em>groupmod &#8211;new-name new_user_name pi<\/em><\/strong><\/p>\n\n\n\n<p>The user pi has the sudo permission which needs to be transferred to new_user, easiest way is to rename the original sudoer file using<\/p>\n\n\n\n<p><strong><em>sudo mv \/etc\/sudoers.d\/010_pi-nopasswd \/etc\/sudoers.d\/new_user_name<\/em><\/strong><\/p>\n\n\n\n<p>now edit the file using<\/p>\n\n\n\n<p><em><strong>nano \/etc\/sudoers.d\/new_user_name<\/strong><\/em><\/p>\n\n\n\n<p>Replace the username pi by new_user_name in<\/p>\n\n\n\n<p><strong>pi ALL=(ALL) NOPASSWD: ALL <\/strong> to <\/p>\n\n\n\n<p><strong>new_user_name ALL=(ALL) NOPASSWD: ALL<\/strong><\/p>\n\n\n\n<p>logout as root and login as the new_user using the password used for user &#8216;pi&#8217;<\/p>\n\n\n\n<p>disable root login through SSH by re-editing the sshd config as above and replacing <strong>PermitRootLogin no&#8217;<\/strong> in the sshd_config<\/p>\n\n\n\n<p>Disable the root user by locking the account again by issuing<\/p>\n\n\n\n<p><strong><em>sudo passwd -l root<\/em><\/strong><\/p>\n\n\n\n<p>Reboot or restart ssh and we are done.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Half of the hackers work is already done when he knows the user neame of te target. This flaw is present in most of the entry level routers, and cannot be changed. Raspberry OS (Raspbian) ships with the default user PI, this user name has to be changed if we want to secure out Pi [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[7,8],"_links":{"self":[{"href":"https:\/\/memoirs.vu2aie.in\/index.php?rest_route=\/wp\/v2\/posts\/89"}],"collection":[{"href":"https:\/\/memoirs.vu2aie.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/memoirs.vu2aie.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/memoirs.vu2aie.in\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/memoirs.vu2aie.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=89"}],"version-history":[{"count":10,"href":"https:\/\/memoirs.vu2aie.in\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":99,"href":"https:\/\/memoirs.vu2aie.in\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions\/99"}],"wp:attachment":[{"href":"https:\/\/memoirs.vu2aie.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/memoirs.vu2aie.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/memoirs.vu2aie.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}