设为首页 收藏本站
查看: 439|回复: 0

[经验分享] 使用命令icacls来备份与恢复NTFS权限

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-1-16 08:54:45 | 显示全部楼层 |阅读模式
背景介绍:

蛋疼客户Windows 2008 R2移除IUSR_LCHAS028针对文件夹和文件的写权限。如下:
1
File "C:INETPUBWWWROOTESPjs        iny_mcepluginssearchreplacelangs". User IUSR_LCHAS028 has wrong permissions: Full access. Must have no Write access.




一共好几千条的记录。。。

可以通过使用图形界面的权限管理来完成,但teamlead非要使用命令和脚本来实现(显得高大上?)

Boss发话了,只能开搞了...........

去Google上搜了下,有相关资料。。。使用命令icacls来实现。

=======================我是分割线===========================

写了个批处理脚本,如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
::#+-------------------------------------------------------------------+  
::#| = : = : = : = : = : = : = : = : = : = : = : = : = : = : = : = : = |  
::#|{>/-------------------------------------------------------------<}|           
::#|: | Author:  Anson Liu                                                   
::#| :| Email:   liuzsz@cn.ibm.com/Anson.liu@live.com
::#| :| Date:    4:00:00 PM 1/15/2015
::#| :|
::#| :|
::#|: | Purpose:                 
::#| :|       Backup, Remove, Restore the permission for folder and file.
::#|: |                                          
::#|: |                                          
::#| :|      /^(o.o)^    Version: 1      
::#|{>-------------------------------------------------------------/<}|
::#| = : = : = : = : = : = : = : = : = : = : = : = : = : = : = : = : = |
::#+-------------------------------------------------------------------+
cls
@ECHO OFF
CLS
color 0a

::set variable for path
set PATH=C:win                ::change to the target path according your environment
set BACK_PERMISSION=c:         ::change to the location for backup permission

GOTO MENU
:MENU
ECHO.
ECHO.               =-=-=-=-=Manage the permission for folder and file=-=-=-=-=
ECHO.
ECHO.                       1  Backup the permission
ECHO.
ECHO.                       2  Remove the permission
ECHO.
ECHO.                       3  Restore the permission
ECHO.
ECHO.                       4  Exit
ECHO.
ECHO.
ECHO.
echo.                Choose the number:
set /p  ID=
if "%id%"=="1"  goto cmd1
if "%id%"=="2" goto cmd2
if "%id%"=="3" goto cmd3
IF "%id%"=="4"  exit
PAUSE
:cmd1
echo Backup the permission
c:windowssystem32icacls.exe %PATH%*  /save %bACK_PERMISSION%win_backuppemission.txt /T
goto MENU
:cmd2
echo Remove the permission
c:windowssystem32icacls.exe %PATH%  /remove chris /T
GOTO MENU
:cmd3
echo Restore the permission
c:windowssystem32icacls.exe %PATH%  /restore %bACK_PERMISSION%win_backuppemission.txt
GOTO MENU




注意

::set variable
set PATH=C:win                        设置为需要移除的文件夹
set BACK_PERMISSION=c:          这个为权限备份位置



c:windowssystem32icacls.exe %PATH%*  /save %bACK_PERMISSION%win_backuppemission.txt /T

这条命令备份win文件夹及下面子文件夹和文件的权限。


c:windowssystem32icacls.exe %PATH%  /remove chris /T

此条命令是移除Chris针对win文件夹,子文件夹及文件的所有权限。



c:windowssystem32icacls.exe %PATH%  /restore %bACK_PERMISSION%win_backuppemission.txt


还原用户Chris对win文件夹,子文件夹及文件的权限。


======================other knowledge=======================


Using iCACLS
  • To edit a file you must already have the "Change" ACL (or be the file's owner)
  • To use the iCACLS command to change the permissions of a file requires "FULL Control" (or be the file's owner)
  • File "Ownership" will always override all ACL's - you always have Full Control over files that you create.
Inherited folder permissions are displayed as:
OI - Object inherit    - This folder and files. (no inheritance to subfolders) CI - Container inherit - This folder and subfolders. IO - Inherit only      - The ACE does not apply to the current file/directoryThese can also be combined as folllows: (OI)(CI)            This folder, subfolders, and files. (OI)(CI)(IO)        Subfolders and files only.     (CI)(IO)  Subfolders only. (OI)    (IO)        Files only.
So BUILTINAdministrators:(OI)(CI)F means that both files and Subdirectories will inherit 'F' (Fullcontrol)
similarly (CI)R means Directories will inherit 'R' (Read folders only = List permission)
When cacls is applied to the current folder only there is no inheritance and so no output.




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-40907-1-1.html 上篇帖子: linux文件及文件夹权限详解 下篇帖子: Linux终端以及用户登录相关命令
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表