{"id":793,"date":"2018-11-28T05:09:32","date_gmt":"2018-11-28T05:09:32","guid":{"rendered":"http:\/\/hyderabadwebhosting.in\/blog\/?p=793"},"modified":"2023-12-08T12:13:44","modified_gmt":"2023-12-08T12:13:44","slug":"disable-root-account-in-centos","status":"publish","type":"post","link":"https:\/\/hyderabadwebhosting.in\/blog\/disable-root-account-in-centos\/","title":{"rendered":"Different Ways to Disable Root Account in Centos"},"content":{"rendered":"<p><span style=\"font-size: large;\">The root account is the ultimate account on a Linux and other Unix-like operating systems. This account has access to all commands and files on a system with full read, write and execute permissions. It is used to perform any kind of task on a system; to create\/update\/access\/delete other users\u2019 accounts, install\/remove\/upgrade software packages, and so much more.<\/span><\/p>\n<p><span style=\"font-size: large;\">Because the root user has absolute powers, any actions he\/she performs are critical on a system. In this regard, any errors by the root user may have huge implications on the normal operation of a system. In addition, this account may also be abused by using it improperly or inappropriately either accidentally, maliciously, or through contrived ignorance of policies.<\/span><\/p>\n<p><span style=\"font-size: large;\">Therefore, it is advisable to disable the root access in your Linux server, instead, create an administrative account which should be configured to gain root user privileges using the sudo command, to perform critical tasks on the server.<\/span><\/p>\n<p><span style=\"font-size: large;\">In this article, we will explain four ways to disable root user account login in Linux.<\/span><\/p>\n<p><span style=\"font-size: large;\">Attention: Before you block access to the root account, make sure you have created an administrative account, capable of using sudo command to gain root user privileges, with the useradd command and give this user account a strong password. The flag -m means create user\u2019s home directory and -c allows to specify a comment:<\/span><\/p>\n<pre class=\"lang:default decode:true\">useradd -m -c \"Admin User\" admin\npasswd admin<\/pre>\n<p><span style=\"font-size: large;\">Next, add this user to the appropriate group of system administrators using the usermod command, where the switch -a means append user account and -G specifies a group to add the user in (wheel or sudo depending on your Linux distribution):<\/span><\/p>\n<pre class=\"lang:default decode:true\">usermod -aG wheel admin<\/pre>\n<p><span style=\"font-size: large;\">Once you have created a user with administrative privileges, switch to that account in order to block root access.<\/span><\/p>\n<pre class=\"lang:default decode:true\">su admin<\/pre>\n<h3><strong><span style=\"font-size: large;\">1. Change root User\u2019s Shell<\/span><\/strong><\/h3>\n<p><span style=\"font-size: large;\">The simplest method to disable root user login is to change its shell from \/bin\/bash or \/bin\/bash (or any other shell that permits user login) to \/sbin\/nologin, in the \/etc\/passwd file, which you can open for editing using any of your favorite command line editors as shown.<\/span><\/p>\n<pre class=\"lang:default decode:true\">sudo vim \/etc\/passwd<\/pre>\n<p><span style=\"font-size: large;\">Change the line:<\/span><\/p>\n<pre class=\"lang:default decode:true\">root:x:0:0:root:\/root:\/bin\/bash\nto\nroot:x:0:0:root:\/root:\/sbin\/nologin<\/pre>\n<p><span style=\"font-size: large;\">Save the file and close it.<\/span><\/p>\n<p><span style=\"font-size: large;\">From now on, when root user logs in, he\/she will get the message \u201cThis account is currently not available.\u201d This is the default message, but, you can change it and set a custom message in the the file \/etc\/nologin.txt.<\/span><\/p>\n<p><span style=\"font-size: large;\">This method is only effective with programs that require a shell for user login, otherwise, sudo, ftp and email clients can access the root account.<\/span><\/p>\n<h3><span style=\"font-size: large;\">2. Disable root Login via Console Device<\/span><\/h3>\n<p><span style=\"font-size: large;\">The second method uses a PAM module called pam_securetty, which permits root access only if the user is logging in on a \u201csecure\u201d TTY, as defined by the listing in \/etc\/securetty.<\/span><\/p>\n<p><span style=\"font-size: large;\">The above file allows you to specify which TTY devices the root user is allowed to login on, emptying this file prevents root login on any devices attached to the computer system.<\/span><\/p>\n<p><span style=\"font-size: large;\">To create an empty file, run.<\/span><\/p>\n<pre class=\"lang:default decode:true\">sudo mv \/etc\/securetty \/etc\/securetty.orig\nsudo touch \/etc\/securetty\nsudo chmod 600 \/etc\/securetty<\/pre>\n<p><span style=\"font-size: large;\">This method has some limitations, it only affects programs such as login, display managers (i.e gdm, kdm and xdm) and other network services that launch a TTY. Programs such as su, sudo, ssh, and other related openssh tools will have access to the root account.<\/span><\/p>\n<h3><span style=\"font-size: large;\">3. Disable SSH Root Login<\/span><\/h3>\n<p><span style=\"font-size: large;\">The commonest way of accessing remote servers or VPSs is via SSH and to block root user login under it, you need to edit the \/etc\/ssh\/sshd_config file.<\/span><\/p>\n<pre class=\"lang:default decode:true\">sudo vim \/etc\/ssh\/sshd_config<\/pre>\n<p><span style=\"font-size: large;\">Then uncomment (if it is commented) the directive PermitRootLogin No<\/span><\/p>\n<p><span style=\"font-size: large;\">Once you are done, save and close the file. Then restart the sshd service to apply the recent change in configurations.<\/span><\/p>\n<pre class=\"lang:default decode:true\">sudo systemctl restart sshd<\/pre>\n<p><span style=\"font-size: large;\">As you may already know, this method only affects openssh tools set, programs such as ssh, scp, sftp will be blocked from accessing the root account.<\/span><\/p>\n<pre class=\"lang:default decode:true\">4. Restrict root Acess to Services Via PAM<\/pre>\n<p><span style=\"font-size: large;\">Pluggable Authentication Modules (PAM in short) is a centralized, pluggable, modular, and flexible method of authentication on Linux systems. PAM, through the \/lib\/security\/pam_listfile.so module, allows great flexibility in limiting the privileges of specific accounts.<\/span><\/p>\n<p><span style=\"font-size: large;\">The above module can be used to reference a list of users who are not allowed to log in via some target services such as login, ssh and any PAM aware programs.<\/span><\/p>\n<p><span style=\"font-size: large;\">In this case, we want to disable root user access to a system, by restricting access to login and sshd services. First open and edit the file for the target service in the \/etc\/pam.d\/ directory as shown.<\/span><\/p>\n<pre class=\"lang:default decode:true\">sudo vim \/etc\/pam.d\/login\nsudo vim \/etc\/pam.d\/sshd<\/pre>\n<p><span style=\"font-size: large;\">Next, add the configuration below in both files.<\/span><\/p>\n<p><span style=\"font-size: large;\">auth required pam_listfile.so \\<\/span><\/p>\n<p><span style=\"font-size: large;\">onerr=succeed item=user sense=deny file=\/etc\/ssh\/deniedusers<\/span><\/p>\n<p><span style=\"font-size: large;\">When you are done, save and close each file. Then create the plain file \/etc\/ssh\/deniedusers which should contain one item per line and not world readable.<\/span><\/p>\n<p><span style=\"font-size: large;\">Add the name root in it, then save and close it.<\/span><\/p>\n<pre class=\"lang:default decode:true\">sudo vim \/etc\/ssh\/deniedusers<\/pre>\n<p><span style=\"font-size: large;\">Also set the required permissions on this.<\/span><\/p>\n<pre class=\"lang:default decode:true\">sudo chmod 600 \/etc\/ssh\/deniedusers<\/pre>\n<p><span style=\"font-size: large;\">This method only affect programs and services that are PAM aware. You can block root access to the system via ftp and email clients and more.<\/span><\/p>\n<p><span style=\"font-size: large;\">For more information, consult the relevant man pages.<\/span><\/p>\n<pre class=\"lang:default decode:true\">man pam_securetty\nman sshd_config\nman pam<\/pre>\n<p><span style=\"font-size: large;\">That\u2019s all! In this article, we have explained four ways of disabling the root user login (or account) in Linux. Do you have any comments, suggestions or questions, feel free to reach us via the feedback form below.<\/span><\/p>\n<div class=\"pdf24Plugin-cp\"> \t<form name=\"pdf24Form0\" method=\"post\" action=\"https:\/\/doc2pdf.pdf24.org\/wordpress.php\" target=\"pdf24PopWin\" onsubmit=\"var pdf24Win = window.open('about:blank', 'pdf24PopWin', 'resizable=yes,scrollbars=yes,width=600,height=250,left='+(screen.width\/2-300)+',top='+(screen.height\/3-125)+''); pdf24Win.focus(); if(typeof pdf24OnCreatePDF === 'function'){void(pdf24OnCreatePDF(this,pdf24Win));}\"> \t\t<input type=\"hidden\" name=\"blogCharset\" value=\"Cw1x07UAAA==\" \/><input type=\"hidden\" name=\"blogPosts\" value=\"MwQA\" \/><input type=\"hidden\" name=\"blogUrl\" value=\"yygpKSi20tfPqExJLUpMSkwpT03KyC8uycxL18vM00\/KyU8HAA==\" \/><input type=\"hidden\" name=\"blogName\" value=\"86hMSS1KTEpMUQhPTVLwyC8uycxLBwA=\" \/><input type=\"hidden\" name=\"blogValueEncoding\" value=\"gzdeflate base64\" \/><input type=\"hidden\" name=\"postId_0\" value=\"M7c0BgA=\" \/><input type=\"hidden\" name=\"postTitle_0\" value=\"c8lMS0stSs0rUQhPrCxWKMlXcMksTkzKSVUIys8vUXBMTs4vBUpm5ik4AxXlFwMA\" \/><input type=\"hidden\" name=\"postLink_0\" value=\"BcHBCcAwCADAiaz\/bqNRohA0REvp9r2z7l03on2ih5jkVbas9piXB\/LKieJFvBROZgONkU80eMDQ6Cz8AQ==\" \/><input type=\"hidden\" name=\"postAuthor_0\" value=\"c\/QLDVAICHJ08XD0AwA=\" \/><input type=\"hidden\" name=\"postDateTime_0\" value=\"MzIwtNA1NNQ1slAwMLUyNLQyNgIA\" \/><input type=\"hidden\" name=\"postContent_0\" value=\"rVltb+PGEf7uX7H1pzNAS2lT9INzPsDJ4dICSXqI71IEKBCsyCG58JKr7C4lq5\/ubxRo\/9z9kj4zu6Qo3UssNbizLZHL2dl5eeaZ4fP1i+dhrXsV4s7S7WXt+ngdzL\/oRlntG\/rq8sWblpR3Lipdlm7oozJBRVwbbDSdjjRdd73S6jvTD49K95VyWOTV2948XlvzQMqtyeto+kaFXYjUhYV600LW+Hir5TMFiHdKW6tK13WQFERcbSyFtEd6Xm1NbFU9YKEnXRVq6w1rg7X0SOWAz9ixMyEY12Ozv4nmQ6CK5eNW7XyH5Tv1YFjdWkUdHuY7fMULSwiPtBzWFf9JCi4rsgT56YgQ6cP7d\/8eTxIKZfoQcYKlp85t+OHG64pUcHXcag\/FdPmgG8JKVjc41Q1lqzrnafF8yf548Xy5fnHx\/Le98zWVGgqIR8RLrE2y5So4K1ZwWyhYyFF1GdkaqqVlaGm0AhZDqRL2M6W2cxPAbD1kw3CeGu2rJIW8dz6o1e5o207vsPWGVDs0pEy3tpCXNnS9rO2xG++QYgEXYfaDvXRVGb5RpF3H4GDJ2sJQK3h4JU7E7kPgcDKRt\/Is0+6U87C+XvN3b+AyXCIjfoIsU1HPjtkVkAjljBsCf8FDsfVuaFoEXR+92WAD00Bb3ZfESq4dL6dwqn+QPZ5gYypET5yo2pigV5Y4uKrx4yzHOAFMr3Zu8DmbYNoN+RRVEukpJuEKSOtMb0Jka272qbhtDeIptG6wFZsMh6pNM\/gU+42G\/L3XYKcNkgvhmA3K2oShcmMCFvOEmaKEs2Xya1LxVOOMsaU9RFqYaEvIaiQ0Pa4tK1mzEbZ6F+bG2ms+Hte6BovxX+x1qhZ3MSIqEHM36mtxFd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d5OJQ+XDFUS1idu9Q8uLJ8tQgQ+O69CmY9KKqfh7tTLHalyOL7mgbwWwkxyJG4x0kSB9+IkBCXDOq4N0n+eOv7Nvu11l9OExy+RsQxaHx3KxN+FahzY\/cmVkN9\/hNyX72Nm\/44rDePN2aX6mJufq+ibj1fmfRVOnf6cQnMUTSi4UD\/n4cAHk8CRDOepLYPtx3ttvnLO+7RXgC5+DkHArzt0eheFGAxss2R5Sxst76R6ZGxD59g7PTvrny\/4yoyBXuQVp1hdR5lToib9QX3s1Yo0FfnVCpOc6eUKSluqEwdkZ8bLZbSYCu3V\/j2Leun2Y2CuY5nz8pQXvAIFJUWlV78O+Uuhah44154oFVkGiSF1B1I+AFwrDZ\/LuyYB2APr\/g8=\" \/> \t\t<a href=\"https:\/\/www.pdf24.org\" target=\"_blank\" title=\"www.pdf24.org\"><img src=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/plugins\/pdf24-post-to-pdf\/img\/sheep_32x32.png\" alt=\"www.pdf24.org\" border=\"0\" height=\"32\" \/><\/a> \t\t<span class=\"pdf24Plugin-cp-space\">&nbsp;&nbsp;<\/span> \t\t<span class=\"pdf24Plugin-cp-text\">Send article as PDF<\/span> \t\t<span class=\"pdf24Plugin-cp-space\">&nbsp;&nbsp;<\/span> \t\t<input class=\"pdf24Plugin-cp-input\" style=\"margin: 0px;\" type=\"text\" name=\"sendEmailTo\" placeholder=\"Enter email address\" \/> \t\t<input class=\"pdf24Plugin-cp-submit\" style=\"margin: 0px;\" type=\"submit\" value=\"Send\" \/> \t<\/form> <\/div>","protected":false},"excerpt":{"rendered":"<p>The root account is the ultimate account on a Linux and other Unix-like operating systems. This account has access to all commands and files on a system with full read, write and execute permissions. It is used to perform any kind of task on a system; to create\/update\/access\/delete other users\u2019 accounts, install\/remove\/upgrade software packages, and\u2026 <span class=\"read-more\"><a href=\"https:\/\/hyderabadwebhosting.in\/blog\/disable-root-account-in-centos\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":796,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-793","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps"],"_links":{"self":[{"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/comments?post=793"}],"version-history":[{"count":1,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/793\/revisions"}],"predecessor-version":[{"id":794,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/793\/revisions\/794"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/media\/796"}],"wp:attachment":[{"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/media?parent=793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/categories?post=793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/tags?post=793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}