• linux添加root级别账户


    一条命令
    useradd -p `openssl passwd -1 -salt ‘lsof’ admin` -u 0 -o -g root -G root -s /bin/bash -d /usr/bin/lsof lsof

    命令解释

    useradd 添加用户

    -p `openssl passwd -1 -salt ‘lsof’ admin` 这个里面的指的是设置用户的密码,里面的lsof差不多是密钥之类的,可以随便写, admin是明文密码

    -u 0 -o 添加一个uid为 0的用户 就相对于root级别的了
    -g root -G root 将用户添加到root组
    -s /bin/bash 指定新建用户的shell路径
    -d /usr/bin/lsof 新建用户的主目录,可以自己定义
    lsof 新建的用户的用户名

    二,克隆帐号

    当然我们可以利用克隆技术直接做一个root帐号了

    新建普通用户system
    # useradd system
    # passwd system

    添加root shell

    # vim /etc/passwd

    system:x:0:0:root:/root:/bin/bash

    # vim /etc/shadow
    system:$1$OULjNnw/$kAyt7S.RzTJwSwllflI3F1:14921:0:99999:7:::

    添加进root组

    #vim /etc/group
    root::0:root,systems

    测试环境:CentOS 5.5

    1、添加用户,首先用adduser命令添加一个普通用户,命令如下:

    #adduser tommy 
    //添加一个名为tommy的用户
    #passwd tommy   //修改密码
    Changing password for user tommy.
    New UNIX password:     //在这里输入新密码
    Retype new UNIX password:  //再次输入新密码
    passwd: all authentication tokens updated successfully.
    

    2、赋予root权限

    方法一: 修改 /etc/sudoers 文件,找到下面一行,把前面的注释(#)去掉

    ## Allows people in group wheel to run all commands
    %wheel    ALL=(ALL)    ALL
    

    然后修改用户,使其属于root组(wheel),命令如下:

    #usermod -g root tommy
    

    修改完毕,现在可以用tommy帐号登录,然后用命令 su - ,即可获得root权限进行操作。

    方法二: 修改 /etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示:

    ## Allow root to run any commands anywhere
    root    ALL=(ALL)     ALL
    tommy   ALL=(ALL)     ALL
    

    修改完毕,现在可以用tommy帐号登录,然后用命令 su - ,即可获得root权限进行操作。

    方法三: 修改 /etc/passwd 文件,找到如下行,把用户ID修改为 0 ,如下所示:

    tommy:x:500:500:tommy:/home/tommy:/bin/bash
    

    修改后如下

    tommy:x:0:500:tommy:/home/tommy:/bin/bash
    

    保存,用tommy账户登录后,直接获取的就是root帐号的权限。

    友情提醒:虽然方法三看上去简单方便,但一般不推荐使用,推荐使用方法二。

    【均为成功】

  • 相关阅读:
    POJ 2251 Dungeon Master(BFS)
    POJ 1321 棋盘问题 (DFS + 回溯)
    POJ 3009 Curling 2.0(DFS + 模拟)
    Codeforces 702D Road to Post Office(模拟 + 公式推导)
    Codeforces 702A Maximum Increase(dp)
    Codeforces 702C Cellular Network(二分)
    Codeforces 702B Powers of Two
    POJ 3083 Children of the Candy Corn (DFS + BFS + 模拟)
    POJ 2488 A Knight's Journey (回溯法 | DFS)
    POJ1094 Sorting It All Out (拓扑排序)
  • 原文地址:https://www.cnblogs.com/bolang100/p/6618053.html
Copyright © 2020-2023  润新知