liunx 创建远程用户帐号

2015-09-07

#add_remote_user.sh
#liunx创建远程用户帐号
#!/bin/bash ### AUTHOR: Joe ### DATE: 2015/08/05 ### REV: 1.0 if [ ! -n "$1" ];then echo -e "Input the username you want grant login privilege to:\c" read username pub_key=$(cat /data/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 -r $username" fi ssh -n $ipadd '(useradd '$username')' ssh -n $ipadd '(mkdir /data/home/'$username'/.ssh)' ssh -n $ipadd '(echo '$pub_key' > /data/home/'$username'/.ssh/authorized_keys)' ssh -n $ipadd '(chown -R '$username' /data/home/'$username'/.ssh)' ssh -n $ipadd '(chmod 700 /data/home/'$username'/.ssh;chmod 600 /data/home/'$username'/.ssh/authorized_keys)' if [ $sudo == yes ];then ssh -n $ipadd "echo -e '$username\tALL=(ALL)\tNOPASSWD: ALL' >>/etc/sudoers" fi ssh -n $ipadd '(chattr +i /etc/passwd /etc/group /etc/shadow /etc/sudoers)' ssh -n $ipadd '(useradd '$username')' ssh -n $ipadd '(mkdir /data/home/'$username'/.ssh)' ssh -n $ipadd '(echo '$pub_key' > /data/home/'$username'/.ssh/authorized_keys)' ssh -n $ipadd '(chown -R '$username' /data/home/'$username'/.ssh)' ssh -n $ipadd '(chmod 700 /data/home/'$username'/.ssh;chmod 600 /data/home/'$username'/.ssh/authorized_keys)' if [ $sudo == yes ];then ssh -n $ipadd "echo -e '$username\tALL=(ALL)\tNOPASSWD: ALL' >>/etc/sudoers" 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 /data/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 /data/home/'$username'/.ssh)' ssh -n $ipadd '(echo '$pub_key' > /data/home/'$username'/.ssh/authorized_keys)' ssh -n $ipadd '(chown -R '$username' /data/home/'$username'/.ssh)' ssh -n $ipadd '(chmod 700 /data/home/'$username'/.ssh;chmod 600 /data/home/'$username'/.ssh/authorized_keys)' if [ $sudo == yes ];then ssh -n $ipadd "echo -e '$username\tALL=(ALL)\tNOPASSWD: ALL' >>/etc/sudoers" 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

 

转载于:https://www.cnblogs.com/cenliang/p/4788724.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值