u
This commit is contained in:
		
							parent
							
								
									47f6ace177
								
							
						
					
					
						commit
						77e27d795f
					
				| @ -2,7 +2,7 @@ | |||||||
| 
 | 
 | ||||||
| echo "Usage: this.sh [NewUser]" | echo "Usage: this.sh [NewUser]" | ||||||
| echo "Example: this.sh alice" | echo "Example: this.sh alice" | ||||||
| echo "curl https://git.faronear.org/fon/sysconfig/raw/branch/main/debian-config.sh | sudo bash" | echo "curl https://git.faronear.org/fon/sysconfig/raw/branch/main/debian-config.sh > ~/debian-config.sh && sudo bash ~/debian-config.sh" | ||||||
| 
 | 
 | ||||||
| if [ v$1 != v ] | if [ v$1 != v ] | ||||||
| then | then | ||||||
| @ -16,18 +16,8 @@ apt update | |||||||
| apt install -y emacs git curl screen sudo automake rsync | apt install -y emacs git curl screen sudo automake rsync | ||||||
| echo | echo | ||||||
| 
 | 
 | ||||||
| echo "=== Making dir /faronear" |  | ||||||
| if [ ! -d "/faronear" ] |  | ||||||
| then |  | ||||||
|   mkdir /faronear |  | ||||||
| fi  |  | ||||||
| echo |  | ||||||
| 
 |  | ||||||
| echo "=== Making dir /faronear/fon" | echo "=== Making dir /faronear/fon" | ||||||
| if [ ! -d "/faronear/fon" ] | mkdir -p /faronear/fon | ||||||
| then  |  | ||||||
|   mkdir /faronear/fon |  | ||||||
| fi |  | ||||||
| echo | echo | ||||||
| 
 | 
 | ||||||
| echo "=== Git cloning to /faronear/fon/sysconfig" | echo "=== Git cloning to /faronear/fon/sysconfig" | ||||||
| @ -39,7 +29,7 @@ fi | |||||||
| echo | echo | ||||||
| 
 | 
 | ||||||
| echo "=== Configure root home" | 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 root | ||||||
| echo | echo | ||||||
| 
 | 
 | ||||||
| echo "=== Change root password? <y> for yes, <anything else> for omit:" | echo "=== Change root password? <y> for yes, <anything else> for omit:" | ||||||
|  | |||||||
| @ -31,12 +31,15 @@ else | |||||||
|   fi |   fi | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| # $2 应当为用户名。为空则默认是 root | # $2 应当为用户名 | ||||||
| if [ "$2" ] | if [ "$2" == 'root' ] | ||||||
|  | then | ||||||
|  |   HomePath=/root | ||||||
|  | elif [ "$2" ] | ||||||
| then | then | ||||||
|   HomePath=/home/$2 |   HomePath=/home/$2 | ||||||
| else | else | ||||||
|   HomePath=/root |   HomePath=~ | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| if [ -d "$HomePath" ] | if [ -d "$HomePath" ] | ||||||
| @ -63,35 +66,30 @@ then | |||||||
|   done |   done | ||||||
|   echo |   echo | ||||||
| 
 | 
 | ||||||
|   if [ $2 ] # 如果 $2 不存在,则默认为是 root 用户,不需要设置 .ssh |   mkdir -p $HomePath/.ssh | ||||||
|  |   chmod 700 $HomePath/.ssh | ||||||
|  |   # 注意,由 root 为新用户创建的配置文件的 owner 是 root,而不是新用户,导致新用户无法读取该文件而密钥登录失败,因此要重设 owner。 | ||||||
|  |   chown $2:$2 $HomePath | ||||||
|  |   if [ -e '$HomePath/.ssh/authorized_keys' ] | ||||||
|   then |   then | ||||||
| 
 |     mv $HomePath/.ssh/authorized_keys $HomePath/.ssh/authorized_keys.backup-$(date +%Y%m%d%H%M%S) | ||||||
|     mkdir -p $HomePath/.ssh |  | ||||||
|     chmod 700 $HomePath/.ssh |  | ||||||
|     # 注意,由 root 为新用户创建的配置文件的 owner 是 root,而不是新用户,导致新用户无法读取该文件而密钥登录失败,因此要重设 owner。 |  | ||||||
|     chown $2:$2 $HomePath |  | ||||||
|     if [ -e '$HomePath/.ssh/authorized_keys' ] |  | ||||||
|     then |  | ||||||
|       mv $HomePath/.ssh/authorized_keys $HomePath/.ssh/authorized_keys.backup-$(date +%Y%m%d%H%M%S) |  | ||||||
|     fi |  | ||||||
| 
 |  | ||||||
|     echo "=== Append or link or omit [$HomePath/.ssh/authorized_keys] to config ssh server? <a> for append, <l> for link, <<anything else>> for omit:" |  | ||||||
|     read -p ">>> " CopyOrLinkOrOmitAuthorizedKeys |  | ||||||
| 
 |  | ||||||
|     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 |  | ||||||
|       chmod 600 $HomePath/.ssh/authorized_keys |  | ||||||
|     fi |  | ||||||
|     echo |  | ||||||
| 
 |  | ||||||
|   fi |   fi | ||||||
| 
 | 
 | ||||||
|  |   echo "=== Append or link or omit [$HomePath/.ssh/authorized_keys] to config ssh server? <a> for append, <l> for link, <<anything else>> for omit:" | ||||||
|  |   read -p ">>> " CopyOrLinkOrOmitAuthorizedKeys | ||||||
|  | 
 | ||||||
|  |   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 | ||||||
|  |     chmod 600 $HomePath/.ssh/authorized_keys | ||||||
|  |   fi | ||||||
|  |   echo | ||||||
|  | 
 | ||||||
|   popd |   popd | ||||||
| else | else | ||||||
|   echo "!!! Not existing $HomePath, please try again." |   echo "!!! Not existing $HomePath, please try again." | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user