码迷,mamicode.com
首页 > 其他好文 > 详细

创建免密码sudo用户

时间:2018-02-11 14:33:33      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:echo   bsp   --   免密   useradd   nbsp   nop   else   gpo   

 

创建免密码sudo用户

#!/bin/bash

c1=`grep -w bkuser /etc/passwd | wc -l`
if [ "$c1" -eq 1 ]; then 
    echo "bkuser已经存在"
    c2=`grep -w bkuser /etc/sudoers | wc -l`
    if [ "$c2" -ge 1 ]; then 
        echo "bkuser sudo成功."
        exit
    else
        echo "bkuser sudo失败"
        cp /etc/sudoers /etc/sudoers.bak.`date +%Y_%m_%d_%S` >/dev/null
        echo "bkuser   ALL=(ALL)       NOPASSWD: ALL" >>/etc/sudoers
        sleep 1
        echo "bkuser sudo已成功添加"
    fi
else
    echo "bkuser不存在"
    useradd bkuser
    echo "1234567" | passwd --stdin bkuser >/dev/null
    cp /etc/sudoers /etc/sudoers.bak.`date +%Y_%m_%d_%S`
    echo "bkuser   ALL=(ALL)       NOPASSWD: ALL" >>/etc/sudoers
    echo "bkuser已经成功添加,且加入sudo"
    sleep 2
    c2=`grep -w bkuser /etc/sudoers | wc -l`
    if [ "$c2" -ge 1 ]; then 
        echo "bkuser sudo成功."
        exit
    else
        echo "bkuser sudo失败"
        cp /etc/sudoers /etc/sudoers.bak.`date +%Y_%m_%d_%S` >/dev/null
        echo "bkuser   ALL=(ALL)       NOPASSWD: ALL" >>/etc/sudoers
        sleep 1
        echo "bkuser sudo已成功添加"
        exit
    fi

fi

 

创建免密码sudo用户

标签:echo   bsp   --   免密   useradd   nbsp   nop   else   gpo   

原文地址:https://www.cnblogs.com/bjx2020/p/8441002.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!