标签:tor inpu top mat $2 cmak ini ssh pass
简单的脚本初始化一个新机器#!/bin/bash
read -p " 输入需要创建的用户名 : " User
www=grep -w "$User" /etc/passwd|awk -F‘:‘ ‘{print $1}‘
Pass=2fZotoQdt0k8nWWs1T8scUbm07dVWSKvZmB672XkG
if [ -z $www ]
then
useradd "$User"
echo "$Pass" | passwd --stdin $User 1> /dev/null
fi
Home=grep -w "$User" /etc/passwd |awk -F‘/‘ ‘{print $2}‘
Bash=grep -w "$User" /etc/passwd |awk -F‘/‘ ‘{print $NF}‘
if [ $Home == home ] && [ $Bash == bash ]
then
echo -e "\n\033[34m sshpass -p ‘$Pass‘ ssh-copy-id -i ~/.ssh/id_rsa.pub -o StrictHostKeyChecking=no $User@hostname -I
\033[0m\n"
echo -e "\033[34m sshpass -p ‘$Pass‘ ssh-copy-id -i ~/.ssh/id_rsa.pub -o StrictHostKeyChecking=no $User@curl -m 10 -s ip.cip.cc
\033[0m\n"
else
usermod -d /home/$User -m $User -s /bin/bash
echo -e "\033[31m usermod To change the\033[0m"
echo -e "\n\033[34m sshpass -p ‘$Pass‘ ssh-copy-id -i ~/.ssh/id_rsa.pub -o StrictHostKeyChecking=no $User@hostname -I
\033[0m\n"
echo -e "\033[34m sshpass -p ‘$Pass‘ ssh-copy-id -i ~/.ssh/id_rsa.pub -o StrictHostKeyChecking=no $User@curl -m 10 -s ip.cip.cc
\033[0m\n"
fi
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
sed -i "s/grep -vE ‘^$|^#|SELINUXTYPE‘ /etc/selinux/config
/SELINUX=disabled/" /etc/selinux/config
yum -y install \
gcc gcc-c++ make autoconf libtool-ltdl-devel gd-devel freetype-devel libxml2-devel \
libjpeg-devel libpng-devel openssl-devel curl-devel bison patch unzip libmcrypt-devel \
libmhash-devel ncurses-devel sudo bzip2 mlocate flex lrzsz sysstat lsof setuptool ntp \
libaio-devel wget nmap finger elinks net-tools telnet curlftpfs bind-utils cmake ncurses \
ncurses-devel zlib zlib-devel bison bison-devel perl perl-devel autoconf automake xz >/dev/null 2>&1
read -p " 需要新的显性主机名么? [Y/y/N/n]: " NAME
case $NAME in
[yY][eE][sS]|[yY])
NAME="yes"
read -p " (输入服务器主机名or角色): " HostName
cat > /etc/motd << EOF
$HostName
如需(启动或重启)服务,请以程序对应普通用户启动
PHP 使用 www 用户
定时任务使用root账户添加到/var/spool/cron/www
EOF
cat >> /etc/bashrc << EOF
PS1="[\${debian_chroot:+(\$debian_chroot)}\u@$HostName - `hostname -I|awk -F" " ‘{print \$1}‘` \w]\\$ "
export USER_IP=`who -u am i 2>/dev/null| awk ‘{print \$NF}‘|sed -e ‘s/[()]//g‘`
export HISTTIMEFORMAT="[%F %T][`whoami`][\${USER_IP}] "
export PROMPT_COMMAND=‘{ msg=\$(history 1 | { read x y; echo \$y; });user=\$(whoami); echo \$(date "+%Y-%m-%d %H:%M:%S"):\$user:`pwd`/:\$msg ---- \$(who am i); } >> /tmp/`date +%F`-`hostname`-`whoami`-history.log‘
alias cd=‘cdp(){ cd \$1;pwd;};cdp‘
EOF
. /etc/bashrc
;;
[nN][oO]|[nN])
NAME="no"
echo "Don‘t need Exit"
;;
*)
echo " Input error, should be [Y/n]."
exit 20
esac
标签:tor inpu top mat $2 cmak ini ssh pass
原文地址:https://blog.51cto.com/amunlinux/2501068