zoukankan      html  css  js  c++  java
  • linux 批量创建远程用户

    2015-09-07

    #add_remote_user_bat.sh
    #linux批量创建远程用户
    #!/bin/bash ### AUTHOR: Joe ### DATE: 2015/07/12 ### REV: 1.0 if [ ! -n "$1" ];then echo -e "Input the username you want grant login privilege to:c" read username pub_key=$(cat /data0/backup/authorized_keys_bak/$username'.pub') echo -e "Input the ip address $username want to login:c" read ipadd echo -e "Whether need root permissions? [yes|no]:c" read sudo ssh -n $ipadd '(chattr -i /etc/passwd /etc/group /etc/shadow /etc/sudoers)' FIND_USER=`ssh -n $ipadd "grep -c $username /etc/passwd"` if [ $FIND_USER -gt 0 ];then ssh -n $ipadd "userdel $username" fi #ssh -n $ipadd '(sed -i "/HOME/s/HOME=/home/HOME=/data/home/g" /etc/default/useradd)' #ssh -n $ipadd '(mkdir -p /data/home)' ssh -n $ipadd '(useradd '$username')' ssh -n $ipadd '(mkdir /home/'$username'/.ssh)' ssh -n $ipadd '(echo '$pub_key' > /home/'$username'/.ssh/authorized_keys)' ssh -n $ipadd '(chown -R '$username' /home/'$username'/.ssh)' ssh -n $ipadd '(chmod 700 /home/'$username'/.ssh;chmod 600 /home/'$username'/.ssh/authorized_keys)' if [ $sudo == yes ];then FIND_SUDO=`ssh -n $ipadd "grep -c $username /etc/sudoers"` if [ $FIND_SUDO -le 0 ];then ssh -n $ipadd "echo -e '$username ALL=(ALL) NOPASSWD: ALL' >>/etc/sudoers" echo "$ipadd sudo privilege has been granted to $username!" else echo "$username's sudo privilege already exist on $ipadd!" fi fi ssh -n $ipadd '(chattr +i /etc/passwd /etc/group /etc/shadow /etc/sudoers)' echo "$ipadd login privilege has been granted to $username!" else echo -e "Input the username you want grant login privilege to:c" read username pub_key=$(cat /data0/backup/authorized_keys_bak/$username'.pub') echo -e "Whether need root permissions? [yes|no]:c" read sudo for ipadd in `cat $1` do ssh -n $ipadd '(chattr -i /etc/passwd /etc/group /etc/shadow /etc/sudoers)' FIND_USER=`ssh -n $ipadd "grep -c $username /etc/passwd"` if [ $FIND_USER -gt 0 ];then ssh -n $ipadd "userdel $username" fi ssh -n $ipadd '(useradd '$username')' ssh -n $ipadd '(mkdir /home/'$username'/.ssh)' ssh -n $ipadd '(echo '$pub_key' > /home/'$username'/.ssh/authorized_keys)' ssh -n $ipadd '(chown -R '$username' /home/'$username'/.ssh)' ssh -n $ipadd '(chmod 700 /home/'$username'/.ssh;chmod 600 /home/'$username'/.ssh/authorized_keys)' if [ $sudo == yes ];then FIND_SUDO=`ssh -n $ipadd "grep -c $username /etc/sudoers"` if [ $FIND_SUDO -le 0 ];then ssh -n $ipadd "echo -e '$username ALL=(ALL) NOPASSWD: ALL' >>/etc/sudoers" echo "$ipadd sudo privilege has been granted to $username!" else echo "$username's sudo privilege already exist on $ipadd!" fi fi ssh -n $ipadd '(chattr +i /etc/passwd /etc/group /etc/shadow /etc/sudoers)' echo "$ipadd login privilege has been granted to $username!" done fi
  • 相关阅读:
    生成随机串码并保存到Excel中
    制作100份word表
    抓取网页图片-以本地IIS网页为实践对象
    使用xlsxwriter 创建图表chart
    照片查看器2.0
    编程注意事项-记踩过的坑
    STC12C5A60S2的定时器模式16位的时候没有自动重载功能
    Keil C51 一个警告 '=': pointer: different mspace
    RT-Thread 使用笔记二
    Keil-C51读取ROM数据
  • 原文地址:https://www.cnblogs.com/cenliang/p/4788764.html
Copyright © 2011-2022 走看看