孙皓宇 發表於 2024-6-7 00:00:00

ubuntu开启root权限和禁用root帐号的方法

<p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        新安装的ubuntu默认不能使用root,需要我们手动开启</p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        在终端中输入:<br/><span style="font-size: 14px; background-color: rgb(221, 237, 251);"></span><span style="font-size: 14px; background-color: rgb(221, 237, 251);"></span></p><pre class="brush:bash;toolbar:false">sudo&nbsp;passwd&nbsp;root
Enter&nbsp;new&nbsp;UNIX&nbsp;password:&nbsp;(在这输入你的密码)
Retype&nbsp;new&nbsp;UNIX&nbsp;password:&nbsp;(确定你输入的密码)
passwd:&nbsp;password&nbsp;updated&nbsp;successfully</pre><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        以后,如果再想获得root权限,只需进行如下的操作:<br/></p><pre class="brush:bash;toolbar:false">su&nbsp;root
Password:&nbsp;(在此输入你上面设置的密码)</pre><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        如果要再次禁用root帐号,那么可以执行</p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        ROOT用户的权限是无限大的,但有时为了一些安全需要我们会把ROOT用户禁止一些功能了,下面一起来看一个Linux中VPS禁止ROOT授权/登录/禁用root用户的方法的文章。</p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        修改ROOT的思路:添加新用户,然后设置该用户为ROOT权限,这样我们以后登录SSH就可以用新用户,这个用户只有我们自己知道,这样就增加了猜测的难度,至此VPS主机的安全进一步得到提升。</p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft=""><strong>第一、新增用户以及设置密码</strong></p><pre class="brush:bash;toolbar:false">useradd&nbsp;itbulucom
passwd&nbsp;itbulucom</pre><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        利用useradd添加用户,passwd给这个用户设置密码,然后会出现添加密码界面,我们输入密码之后回车再输入一次。<br/>
        新增新管理用户<br/></p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft=""><strong>第二、设置权限</strong></p><pre class="brush:bash;toolbar:false">vi&nbsp;/etc/ssh/sshd_config</pre><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        可以用上面的vi命令打开sshd_config 文件修改配置,找到PermitRootLogin把参数yes改成no,然后保存退出。<br/></p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft=""><strong>第三、重启SSH设置</strong></p><pre class="brush:bash;toolbar:false">#centos
/etc/init.d/sshd&nbsp;restart
#debian/ubuntu
/etc/init.d/ssh&nbsp;restart</pre><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        根据我们自己系统的不同选择对应重启SSH命令,重启之后我们再用ROOT是不可以登录了,必须用新设置的itbulucom以及设置的密码才可以登录SSH。如果不信你也可以试试。</p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft=""><strong>补充 禁止root帐号直接登录</strong></p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft=""><strong>一、新建帐户</strong></p><pre class="brush:bash;toolbar:false">useradd&nbsp;kwxgd</pre><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        SSH执行以上命令,可以创建名为“kwxgd”的帐号,可以自定义。<br/></p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft=""><strong>二、设置帐户密码</strong></p><pre class="brush:bash;toolbar:false">passwd&nbsp;kwxgd</pre><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        &nbsp;使用passwd命令即可给相应帐户设置或修改密码。<br/>
        根据图示,设置或修改密码需要填写两次,第二次为效验密码,输入完毕后请回车确认。<br/></p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        三、不允许root直接登陆</p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        1、修改相关文件<br/></p><pre class="brush:bash;toolbar:false">vi&nbsp;/etc/ssh/sshd_config</pre><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        SSH执行以上命令,修改sshd_config文件<br/></p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        2、禁止root登陆<br/>
        查找“#PermitRootLogin yes”,将前面的“#”去掉,短尾“Yes”改为“No”,并保存文件。</p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft=""><strong>四、下次登陆</strong></p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        1、先使用新建账号“kwxgd”以普通用户登陆。<br/>
        2、若要获得ROOT权限,在SSH中执行以下命令<br/></p><pre class="brush:bash;toolbar:false">su&nbsp;root</pre><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        执行以上命令并输入root密码后即可获得root权限。<br/></p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft=""><strong>更安全的做法是禁用ROOT账户</strong></p><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        第一步,我们先SSH 登陆VPS。<br/></p><pre class="brush:bash;toolbar:false">useradd&nbsp;laozuo&nbsp;#添加用户名
passwd&nbsp;laozuo&nbsp;#为laozuo用户名设置密码</pre><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        然后需要输入两次密码,你会看到如图的显示。<br/>
        禁用ROOT账户<br/>
        第二步,就是我们需要设置禁止ROOT用户,这需要编译文件的。我们可以通过VI命令操作,也可以通过WINSCP等FTP软件下载文件编辑。<br/></p><pre class="brush:bash;toolbar:false">vi&nbsp;/etc/ssh/sshd_config</pre><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        和之前的设置端口一样,编译sshd_config文件,把PermitRootLogin中的YES改成NO<br/>
        修改PermitRootLogin<br/>
        保存退出,重启SSH:<br/></p><pre class="brush:bash;toolbar:false">service&nbsp;sshd&nbsp;restart(centos)/service&nbsp;ssh&nbsp;restart(debian)</pre><p style="margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, " microsoft="">
        第三步,提权。用我们新添加的用户名登陆,然后su root 进行提权,让新用户有ROOT用户有的最高权限。<br/></p>
頁: [1]
查看完整版本: ubuntu开启root权限和禁用root帐号的方法