u
This commit is contained in:
		
							parent
							
								
									7f15783d70
								
							
						
					
					
						commit
						cda2881cf5
					
				| @ -41,7 +41,6 @@ else | |||||||
| fi | fi | ||||||
| echo | echo | ||||||
| 
 | 
 | ||||||
| # 注意,由 root 为新用户创建的配置文件的 owner 是 root,而不是新用户 |  | ||||||
| if [ $NewUser = 'adot' ] | if [ $NewUser = 'adot' ] | ||||||
| then | then | ||||||
|   source /faronear/fon/sysconfig/home-config.sh /faronear/fon/sysconfig/nixhome $NewUser |   source /faronear/fon/sysconfig/home-config.sh /faronear/fon/sysconfig/nixhome $NewUser | ||||||
|  | |||||||
| @ -41,14 +41,18 @@ echo "=== Configure root home" | |||||||
| source /faronear/fon/sysconfig/home-config.sh /faronear/fon/sysconfig/nixhome | source /faronear/fon/sysconfig/home-config.sh /faronear/fon/sysconfig/nixhome | ||||||
| echo | echo | ||||||
| 
 | 
 | ||||||
| echo "=== Change root password" | echo "=== Change root password? <y> for yes, anything else for omit:" | ||||||
|  | read -p ">>> " ChangeRootPassword | ||||||
|  | if [ "$ChangeRootPassword" == 'y' ] | ||||||
|  | then | ||||||
|   passwd |   passwd | ||||||
|  | fi | ||||||
| echo  | echo  | ||||||
| 
 | 
 | ||||||
| echo "=== Configure /etc/sudoers" | echo "=== Configure /etc/sudoers" | ||||||
| chmod o+w /etc/sudoers | chmod o+w /etc/sudoers | ||||||
| #sed -i "s|%sudo\s\+ALL=(ALL:ALL)\sALL|%sudo\tALL=(ALL:ALL) NOPASSWD:ALL|g" /etc/sudoers  # allow all users in %sudo group to sudo without password | #sed -i "s|%sudo\s\+ALL=(ALL:ALL)\sALL|%sudo\tALL=(ALL:ALL) NOPASSWD:ALL|g" /etc/sudoers  # allow all users in %sudo group to sudo without password | ||||||
| sed -i "s|#includedir /etc/sudoers.d|includedir /etc/sudoers.d|g" /etc/sudoers  # allow users in /etc/sudoers.d/ folder to sudo | sed -i "s|#includedir /etc/sudoers.d|@includedir /etc/sudoers.d|g" /etc/sudoers  # allow users in /etc/sudoers.d/ folder to sudo | ||||||
| chmod o-w /etc/sudoers | chmod o-w /etc/sudoers | ||||||
| echo | echo | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -61,26 +61,25 @@ then | |||||||
|   echo |   echo | ||||||
|   echo "=== Append or link or omit [.ssh/authorized_keys] to config ssh server? <a> for append, <l> for link, <<anything else>> for omit:" |   echo "=== Append or link or omit [.ssh/authorized_keys] to config ssh server? <a> for append, <l> for link, <<anything else>> for omit:" | ||||||
|   read -p ">>> " CopyOrLinkOrOmitAuthorizedKeys |   read -p ">>> " CopyOrLinkOrOmitAuthorizedKeys | ||||||
|   if [ "$CopyOrLinkOrOmitAuthorizedKeys" = 'l' ] | 
 | ||||||
|   then |  | ||||||
|     echo "--- Linking $SourcePath/authorized_keys to $HomePath/.ssh/authorized_keys ..." |  | ||||||
|   mkdir -p $HomePath/.ssh |   mkdir -p $HomePath/.ssh | ||||||
|   chmod 700 $HomePath/.ssh |   chmod 700 $HomePath/.ssh | ||||||
|     chown adot:adot .ssh |   if [ "$2" ] # 注意,由 root 为新用户创建的配置文件的 owner 是 root,而不是新用户,导致新用户无法读取该文件而密钥登录失败,因此要重设 owner。 | ||||||
|     mv $HomePath/.ssh/authorized_keys $HomePath/.ssh/authorized_keys.backup-$(date +%Y%m%d%H%M%S) |  | ||||||
|     ln -s $SourcePath/.ssh/authorized_keys $HomePath/.ssh/authorized_keys |  | ||||||
|   elif [ "$CopyOrLinkOrOmitAuthorizedKeys" = 'a' ] |  | ||||||
|   then |  | ||||||
|     mkdir -p $HomePath/.ssh |  | ||||||
|     chmod 700 $HomePath/.ssh |  | ||||||
|     if [ "$2" ] |  | ||||||
|   then |   then | ||||||
|     chown $2:$2 $HomePath |     chown $2:$2 $HomePath | ||||||
|   fi |   fi | ||||||
|     if [ -L '$HomePath/.ssh/authorized_keys' ] |   if [ -e '$HomePath/.ssh/authorized_keys' ] | ||||||
|   then |   then | ||||||
|       mv $HomePath/.ssh/authorized_keys $HomePath/.ssh/authorized_keys.backup |     mv $HomePath/.ssh/authorized_keys $HomePath/.ssh/authorized_keys.backup-$(date +%Y%m%d%H%M%S) | ||||||
|   fi |   fi | ||||||
|  | 
 | ||||||
|  |   if [ "$CopyOrLinkOrOmitAuthorizedKeys" = 'l' ] | ||||||
|  |   then | ||||||
|  |     echo "--- Linking $SourcePath/authorized_keys to $HomePath/.ssh/authorized_keys ..." | ||||||
|  |     ln -s $SourcePath/.ssh/authorized_keys $HomePath/.ssh/authorized_keys | ||||||
|  |   elif [ "$CopyOrLinkOrOmitAuthorizedKeys" = 'a' ] | ||||||
|  |   then | ||||||
|  |     echo "--- Copying $SourcePath/authorized_keys to $HomePath/.ssh/authorized_keys ..." | ||||||
|     cat $SourcePath/.ssh/authorized_keys >> $HomePath/.ssh/authorized_keys |     cat $SourcePath/.ssh/authorized_keys >> $HomePath/.ssh/authorized_keys | ||||||
|     chmod 600 $HomePath/.ssh/authorized_keys |     chmod 600 $HomePath/.ssh/authorized_keys | ||||||
|   fi |   fi | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user