AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[scripting](server)

Martin Hope
user2328273
Asked: 2024-08-16 06:15:01 +0800 CST

移动文件时使用目标文件名与目标目录会产生审计日志记录难题

  • 5

我正在尝试使用 auditd (audit 4.0.1) 记录文件操作,并遇到了移动文件的问题。如果我在目标中包含文件名:

mv /mnt/user/home/file.txt /mnt/user/home/Folder1/file.txt

我明白了:

type=SYSCALL msg=audit(1723755217.700:367): syscall=264 success=yes exit=0 a0=ffffff9c a1=7ffcad79d745 a2=ffffff9c a3=7ffcad79d763 items=4 ppid=402506 pid=763811 comm="mv" exe="/bin/mv" SYSCALL=renameat 
type=CWD msg=audit(1723755217.700:367): cwd="/usr/local"
type=PATH msg=audit(1723755217.700:367): item=0 name="/mnt/user/home/Folder1/" inode=11540474087238444 nametype=PARENT 
type=PATH msg=audit(1723755217.700:367): item=1 name="/mnt/user/home/" inode=11540474084530994 nametype=PARENT 
type=PATH msg=audit(1723755217.700:367): item=2 name="/mnt/user/home/file.txt" inode=652740471477682549 nametype=DELETE 
type=PATH msg=audit(1723755217.700:367): item=3 name="/mnt/user/home/Folder1/file.txt" inode=652740471477682549 nametype=CREATE 
type=PROCTITLE msg=audit(1723755217.700:367): proctitle=mv /mnt/user/home/file.txt /mnt/user/home/Folder1/file.txt
type=EOE msg=audit(1723755217.700:367):

但如果我只包含目标文件夹:

mv /mnt/user/home/file.txt /mnt/user/home/Folder1/

我得到两个系统调用:

type=SYSCALL msg=audit(1723755697.454:465): syscall=257 success=yes exit=3 a0=ffffff9c a1=7ffc55b2276c a2=210000 a3=0 items=1 comm="mv" exe="/bin/mv" SYSCALL=openat 
type=CWD msg=audit(1723755697.454:465): cwd="/usr/local"
type=PATH msg=audit(1723755697.454:465): item=0 name="/mnt/user/home/Folder1/" inode=11540474087238444 nametype=NORMAL 
type=PROCTITLE msg=audit(1723755697.454:465): proctitle=mv /mnt/user/home/file.txt /mnt/user/home/Folder1/
type=EOE msg=audit(1723755697.454:465):

type=SYSCALL msg=audit(1723755697.455:466): syscall=264 success=yes exit=0 a0=ffffff9c a1=7ffc55b2274a a2=3 a3=4270fa items=4 comm="mv" exe="/bin/mv" SYSCALL=renameat 
type=CWD msg=audit(1723755697.455:466): cwd="/usr/local"
type=PATH msg=audit(1723755697.455:466): item=0 name="/usr/local" inode=11540474087238444 nametype=PARENT 
type=PATH msg=audit(1723755697.455:466): item=1 name="/mnt/user/home/" inode=11540474084530994 nametype=PARENT 
type=PATH msg=audit(1723755697.455:466): item=2 name="/mnt/user/home/file.txt" inode=652740471477682549 nametype=DELETE 
type=PATH msg=audit(1723755697.455:466): item=3 name="file.txt" inode=652740471477682549 nametype=CREATE 
type=PROCTITLE msg=audit(1723755697.455:466): proctitle=mv /mnt/user/home/file.txt /mnt/user/home/Folder1/
type=EOE msg=audit(1723755697.455:466):

使用目录作为目标并且不包含文件名意味着它将仅保留相同的文件名,但我不确定如何解析这种情况。第一种情况很简单,项目 2 和 3 是源和目标。第二种情况创建一个openat系统调用,然后创建一个renameat系统调用,并且renameat系统调用的结构不同。所有项目都没有目标目录;那是在openat系统调用中。我本来不打算将其包括openat在我的审计规则中,因为我不需要它,而且无论如何都有太多的调用。但现在我必须弄清楚如何处理这种奇怪的情况。我还没有找到可能遇到过这种情况的其他人的任何解决方案。这是我使用的规则,也是唯一的规则:

-a always,exit -F arch=b64 -S all -F dir=/mnt/user/home/ -F success=1

我必须将其扩展以进行故障排除,因为正如我所说,我并不是在寻找openat系统调用。我能想到的唯一方法是包含openat并以某种方式链接和openat系统renameat调用,过滤掉任何openat不匹配的调用。但问题是我的脚本目前基于每个事件工作,而这是两个事件。我确信还有更多我甚至没有想到的问题。有什么关于如何处理这个问题的想法吗?

scripting
  • 1 个回答
  • 40 Views
Martin Hope
stackprotector
Asked: 2022-04-21 08:44:23 +0800 CST

如何以编程方式设置“其他域支持 Kerberos AES 加密”设置?

  • 0

在 GUI(Active Directory 域和信任MMC 管理单元 ( domain.msc))中,您可以为信任关系设置“其他域支持 Kerberos AES 加密”设置:

其他域支持 Kerberos AES 加密

我正在寻找一种以编程方式设置此设置的方法。我已经查看了Install-ADDSDomainPowerShell cmdlet 以及该netdom TRUST工具,但两者似乎都不包含设置Kerberos AES 加密设置的选项。

有人可以告诉我,如何以编程方式设置此设置?

windows scripting kerberos windows-server-2019 trust-relationship
  • 1 个回答
  • 867 Views
Martin Hope
AmelieAudet
Asked: 2022-03-31 04:49:30 +0800 CST

继续声明不能正常工作 - bash

  • 0

对于上下文,我有一个使用 ssh 的多台机器的基础设施。我们通过 ssh 在没有密码的机器上以 root 身份连接,感谢每台机器上的 authorized_keys 文件。我们定期在我们的基础设施中添加新机器。

有问题的是创建一个脚本:

  1. ping 所有机器(通过解析包含我们所有机器名称的文件)
  2. 如果 ping 成功,请在没有密码的情况下测试 ssh 连接(使用命令ssh -o BatchMode=yes $machine uname -a)
  3. 如果 ssh 不起作用并且是因为此消息:(Are you sure you want to continue connecting (yes/no)?例如,因为它是与这台机器的第一个 ssh 连接),那么使用期望脚本,发送“yes”
  4. 如果 ssh 不起作用并且是因为要求输入密码,那么使用期望脚本,发送“CTRL + C”

我的问题是这两个条件 3. 和 4. 都可能发生在一台机器上,我不知道如何在我的脚本中使用 continue 语句。

这种特定情况适用于要求“是”但之后也要求输入密码的机器。

这是脚本的样子:

for machine in `cat ${liste} | grep -v \#`
do

ping -c1 ${machine} 2>&1 >/dev/null

if [ $? -eq 0 ]
then
    echo ${machine} >> ${pingok}    
    ssh -o BatchMode=yes ${machine} uname -a &> $verifssh 2>&1    
    echo $? > ${exitcode}
    
    if grep -q "255" "$exitcode"
    then        
        cut -c 15-74 $verifssh > $verifssh2
                
        if grep "ication failed." "$verifssh2"        
        then                
            expect ${scriptexpectknownhosts} ${machine} 2>&1 >/dev/null
            
            continue 3 
                        
        elif grep "Permission denied (publickey,password,keyboard-interactive)." "$verifssh2"        
        then        
            expect ${scriptexpectknownhosts} ${machine} 2>&1 >/dev/null            
            echo "${machine}   ->  The machine asks for a password" >> "${sshnok}"           
        fi
                
    elif grep -q "0" "$exitcode"   
    then   
        echo "${machine} works with ssh"
        echo "${machine}" >> ${sshok}               
    fi
    
else
    echo "${machine}" >> "${pingnok}"     
fi

done

这是期望脚本(它处理这两种情况):

set machine [lindex $argv 0]

spawn ssh $machine

expect {
    "Are you sure you want to continue connecting (yes/no)? "  {send "yes\r";exp_continue}
    -exact "Password: " {close}
    -re $prompt {send "exit\r";close}
}

所以简而言之,我的问题是,对于要求“是”答案然后需要密码的机器,我想在${sshnok}文件中注册它们但continue不起作用。我试过continue//它仍然不想回到上一个循环continue 2。continue 3

linux scripting bash ssh expect
  • 1 个回答
  • 87 Views
Martin Hope
agsamek
Asked: 2022-01-30 00:06:24 +0800 CST

如何使用虚拟化/LAMP(小型 IaC)自动安装服务器?

  • -1

如何自动化服务器安装?哪些基础设施/系统适合我们的需求?

我们有 10 多台物理服务器和 100 多台虚拟机,主要是 LAMP。不是太多,但也不是任何可以自己继续工作的东西。所有服务器都有 KVM 虚拟化。我们为经常修改的客户托管各种定制应用程序。因此,这不是一个需要扩展的应用程序。项目团队直接与客户和虚拟机合作,这是一项要求。

我们经常遇到的问题是重新安装虚拟机/机器会变得很棘手,因为没有人控制它们最近的更改,这会带来不稳定的风险,人们会尽可能地推迟它,并且随着时间的推移问题会变得更大。

我想至少每 3 个月根据需要建立一个重新安装程序。重新安装应从代码存储库和备份开始。这不应该是虚拟机重复。

我们估计,如果手动完成,在当前设置中每 3 个月将花费我们大约 6 个人工月。我们如何才能减少这个时间并增加过程的可重复性?

问题是什么软件可以帮助我们自动完成这项任务。它应该尽可能轻。我们不需要自动节点分配。我们只需要重新安装以尽可能自动化。我们假设每次重新安装都有人工监督。

我们的节点主要是 LAMP,有两个系统具有超过 1TB 的结构化数据库数据、几个 >200GB 和大约 50 个小型自定义 VM。我们可以轻松地安排每个系统的计划停机时间,因此这不是重新安装期间的高可用性问题。

我们只需要尽可能地自动重新安装。

scripting debian installation
  • 2 个回答
  • 60 Views
Martin Hope
Andrew Savinykh
Asked: 2022-01-28 16:10:24 +0800 CST

如何编写脚本检查 known_hosts 文件中的密钥是否正确

  • 1

我想在脚本中实现一个函数,该函数检查与 known_hosts 文件中给定主机对应的密钥是否正确。显而易见的方法是尝试 ssh 连接并解析它是否会导致 known_hosts 警告。由于以下原因,这是次优的:

  • 如果主机不在know_hosts 文件中,则需要单独检查
  • 它依赖于可能会更改的警告的特定措辞
  • 它在您不需要运行的目标服务器上为您运行一个 ssh 命令,并且可能由于不同的原因(例如指定的登录 shell)而失败
  • 需要有效的凭据

我试图找到可能用于该检查的选项ssh-keyscan和ssh-keygen命令,但没有找到它们。

进行此检查的最简单方法是什么?

scripting ssh
  • 3 个回答
  • 119 Views
Martin Hope
PersianGulf
Asked: 2021-12-25 23:28:36 +0800 CST

在 vCenter 上编写 shell 脚本或其他脚本

  • 0

esxcli存在于vSphere。但我需要编写脚本vCenter并且vCenter没有esxcli命令。
我该如何编写脚本vCenter?

scripting vmware-vcenter vmware-esxi
  • 2 个回答
  • 209 Views
Martin Hope
Gilberto Martins
Asked: 2021-11-23 11:52:28 +0800 CST

Windows 2019 .BAT 脚本中的奇怪行为

  • 1

我必须将备份从 Linux MariaDB 恢复到 Windows MariaDB,PowerBI 网关将在其中导入其数据。“mariabackup”是 MariaDB 的物理备份工具。但要恢复它,目标文件夹 ( %programfiles%\MariaDB 10.3\data\) 必须为空。

由于rmdir /S /Q "%programfiles%\MariaDB 10.3\data\将删除“数据”目录(我不想要的!!!),我一直在努力避免在以下脚本(uncompress.bat)中出现这种不需要的行为:

rem Uncompress the backup sent by the linux server
rem and imports it to MariaDB
rem Gilberto Martins - 19/11/2021

rem Uncompress the backup
rem The backup path is "mnt\external01\"
tar -xf c:\users\mariabkp\bkp.tgz -C c:\users\mariabkp\

rem Stop MariaDB
net stop mysql

rem Prepare the Backup for Restoration
"C:\Program Files\MariaDB 10.3\bin\mariabackup.exe" --prepare --target-dir="c:\users\mariabkp\mnt\external01\backup"\

rem Erase the Database files
del /q "C:\Program Files\MariaDB 10.3\data\*.*"
FOR /D %p IN ("c:\Program Files\MariaDB 10.3\data\*") DO rmdir "%p" /s /q

rem Import backup to MariaDB
"C:\Program Files\MariaDB 10.3\bin\mariabackup.exe" --move-back --target-dir="c:\users\mariabkp\mnt\external01\backup"\

rem Restore MariaDB conf file
copy "c:\Users\Administrator\my.ini" "c:\Program Files\MariaDB 10.3\data" /y

rem Start MariaDB
net start mysql

我工作得很好,直到我必须删除要恢复的文件,正如您在前面看到的那样:

Microsoft Windows [Version 10.0.17763.1935]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\Administrator>uncompress.bat

C:\Users\Administrator>rem Uncompress the backup sent by the linux server

C:\Users\Administrator>rem and imports it to MariaDB

C:\Users\Administrator>rem Gilberto Martins - 19/11/2021

C:\Users\Administrator>rem Uncompress the backup

C:\Users\Administrator>rem The backup path is "mnt\external01\backup"

C:\Users\Administrator>tar -xf c:\users\mariabkp\bkp.tgz -C c:\users\mariabkp\

C:\Users\Administrator>rem Stop MariaDB

C:\Users\Administrator>net stop mysql
The MySQL service is stopping.
The MySQL service was stopped successfully.


C:\Users\Administrator>rem Prepare the Backup for Restoration

C:\Users\Administrator>"C:\Program Files\MariaDB 10.3\bin\mariabackup.exe" --prepare --target-dir="c:\users\mariabkp\mnt\external01\backup"\
C:\Program Files\MariaDB 10.3\bin\mariabackup.exe based on MariaDB server 10.3.31-MariaDB Win64 (AMD64)
[00] 2021-11-22 16:26:29 cd to c:\users\mariabkp\mnt\external01\backup\
[00] 2021-11-22 16:26:29 open files limit requested 0, set to 0
[00] 2021-11-22 16:26:29 This target seems to be not prepared yet.
[00] 2021-11-22 16:26:29 mariabackup: using the following InnoDB configuration for recovery:
[00] 2021-11-22 16:26:29 innodb_data_home_dir = .
[00] 2021-11-22 16:26:29 innodb_data_file_path = ibdata1:12M:autoextend
[00] 2021-11-22 16:26:29 innodb_log_group_home_dir = .
[00] 2021-11-22 16:26:29 Starting InnoDB instance for recovery.
[00] 2021-11-22 16:26:29 mariabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
2021-11-22 16:26:29 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
2021-11-22 16:26:29 0 [Note] InnoDB: Uses event mutexes
2021-11-22 16:26:29 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-11-22 16:26:29 0 [Note] InnoDB: Number of pools: 1
2021-11-22 16:26:29 0 [Note] InnoDB: Using SSE2 crc32 instructions
2021-11-22 16:26:29 0 [Note] InnoDB: Initializing buffer pool, total size = 100M, instances = 1, chunk size = 100M
2021-11-22 16:26:29 0 [Note] InnoDB: Completed initialization of buffer pool
2021-11-22 16:26:29 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=7032026737757
2021-11-22 16:26:29 0 [Note] InnoDB: Starting final batch to recover 68 pages from redo log.
[00] 2021-11-22 16:26:30 Last binlog file , position 0
[00] 2021-11-22 16:26:31 completed OK!

C:\Users\Administrator>rem Erase the Database files

C:\Users\Administrator>del /q "C:\Program Files\MariaDB 10.3\data\*.*"
\Program was unexpected at this time.

C:\Users\Administrator>FOR /D \Program Files\MariaDB 10.3\data\*") DO rmdir "p" /s /q

C:\Users\Administrator>

我的问题:

  1. 为什么\Program was unexpected at this time.当我尝试时出现消息del /q "C:\Program Files\MariaDB 10.3\data\*.*"

  2. 为什么原始指令FOR /D %p IN ("c:\Program Files\MariaDB 10.3\data\*") DO rmdir "%p" /s /q回显为FOR /D \Program Files\MariaDB 10.3\data\*") DO rmdir "p" /s /q?看起来(但我不确定)它可能与“%p”变量有关。

  3. 为什么剩下的指令(导入备份、恢复 my.ini 和启动 MariaDB)没有执行?

我不得不承认,我是 Windows 脚本的新手。而且我认为没有必要为一个脚本安装完整的 Python3!

更新:我试图在“准备备份以进行恢复”之前“擦除数据库文件”,但我得到了相同的结果,即它在“FOR”指令处停止。

windows scripting batch mariadb
  • 1 个回答
  • 64 Views
Martin Hope
Zareh Kasparian
Asked: 2021-11-06 03:21:11 +0800 CST

“command.sh > /dev/null 2>&1”与“command.sh 2>&1 >/dev/null”有什么区别

  • 0

我的 crontab 上有许多 shell 和 python 脚本,它们以以下任一结尾:

command.sh > /dev/null 2>&1

或者

command.sh 2>&1 >/dev/null

我知道:

> 用于重定向

/dev/null是一个黑洞,任何发送的数据都会被丢弃

2是标准错误的文件描述符

>用于重定向

&是文件描述符的符号(没有它,以下 1 将被视为文件名)

1是标准输出的文件描述符

因此command.sh >/dev/null 2>&1将我的程序的输出重定向到/dev/null。包括标准错误和标准输出。

两者都有相同的结果并且工作正常,但是为什么有些人使用第一种类型而有些人使用另一种呢?

linux scripting shell-scripting
  • 1 个回答
  • 166 Views
Martin Hope
Ror
Asked: 2021-07-29 01:48:31 +0800 CST

安全重启多个远程服务器上的服务

  • 0

我需要编写一个脚本,以便我和我的同事可以在多台服务器上重新启动不同的服务。我们都使用 LDAP 连接到服务器,所以我希望我的脚本将我们的 LDAP 用户连接到服务器,然后使用 sudo 重新启动服务(我可以在每台服务器上编写一个脚本来重新启动所有需要的服务)。现在脚本只需运行类似的命令

ssh -t user@host "sudo service XXX restart" 

问题在于,对于每台服务器,脚本都会两次询问用户密码(一次用于 ssh 连接,两次用于 sudo 命令)。我的第一个猜测是使用 read -s -p 提示用户输入登录名和密码,然后使用该变量自动使用 ssh 登录。显然,Expect 是执行此操作的方法,但我没有找到在 Expect 脚本中安全地提示密码或在 bash 脚本中提示密码并在 expect 脚本中安全地传递变量的方法。

我确实查找了诸如 pssh、集群 ssh 之类的解决方案,这些解决方案似乎可以正常工作,但不适用于 sudo。我知道最好的方法是使用 ssh 密钥,但由于多个用户需要使用脚本,我想使用 LDAP 登录名/密码。

scripting security bash ssh expect
  • 1 个回答
  • 89 Views
Martin Hope
Anoduck
Asked: 2021-06-01 01:09:30 +0800 CST

任何人都知道脚本、程序等...来检查文件夹/文件权限和修复/恢复?

  • 1

我不是新手。我是一名专业人士,向其他专业人士寻求快速解决常见问题的方法,我知道是什么chmod -R。
这是对我的问题立即给予-1评级的回应,对于那些可能对我的调查的严肃性不屑一顾或否认其有效性的人来说。


在我的桌面和以 root 身份运行 Kali linux 的远程服务器之间试验 sshfs(Kali 的默认设置)。设法破解系统上的所有文件和文件夹权限/所有权。我已经设法修复了一些,chmod -R 0755 在适当的地方用一个简单的,但注意到很多仍然没有修复。

想知道是否有 bash 脚本或其他脚本或程序可以帮助恢复正确的所有者和权限?

我找到了一个类似的脚本,但它主要用于修复主目录。

脚本,如下:

#!/bin/bash
read -r -p "Correct file and folder permissions? [y/N] " chse
if [[ "$chse" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
  echo "Processing ..."
  find -H $(pwd) -type d -exec chmod 0755 {} \;
  # set dirs to 755
  find -H $(pwd) -type f \( -iname '*.so.*' -o -iname '*.so' \) -exec chmod 0644 {} \;
  # libs
  IFS=$'\n'
  for value in $(find -H $(pwd) -type f ! \( -iname '*.so.*' -o -iname '*.so' -o -iname '*.bak' \) -printf '%p\n'); do
    tstbin=$(readelf -l "$value" 2>/dev/null | grep -Pio 'executable|shared')
    if [ -z "$tstbin" ]; then
      tstbat=$(cat "$value" | head -c2 | grep -io '#!')
      if [ -n "$tstbat" ]; then
        perm=$(stat -c '%a' "$value")
        if [ "$perm" != "755" ]; then
          chmod 755 $value
          echo "Set script  755 $value"
          # set batch to 755
        fi
      else
        perm=$(stat -c '%a' "$value")
        if [ "$perm" != "644" ]; then
          chmod 644 $value
          echo "Set regular 644 $value"
          # set regular files to 644
        fi
      fi
      # above aren't elf binary
    else
      perm=$(stat -c '%a' "$value")
      if [ "$perm" != "755" ]; then
        chmod 755 $value
        echo "Set binary  755 $value"
        # set elf binaries to 755
      fi
    fi
  done
  unset IFS
  # process linux permissions for files and folders
else
  echo "Aborted."
fi

有没有人发现任何更重要的东西可以修复文件系统的权限和所有权?


--> Update: <--

没有找到理想的解决方案,我已着手修改上述脚本并使其有助于我想要的解决方案:

permafix.sh - github 上的要点

#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'


# ====================================================================
# --> Documentation <--
# ---------------------
#
# 0755 21 root root  .
# 0755 21 root root  ..
# 0755  2 root root  bin
# 0755  4 root root  boot
# 0755 15 root root  dev
# 0755 53 root root  etc
# 0755  4 root root  home
# 0755  7 root root  lib
# 0700  2 root root  lost+found
# 0755  6 root root  media
# 0755  2 root root  mnt
# 0755  4 root root  opt
# dr-xr-xr-x 87 root root  proc # Not touching this.
# 0744  8 root root  root
# 0755  2 root root  sbin
# 0755  3 root root  share
# 0755  4 root root  srv
# 0755 12 root root  sys
# 1777  7 root root  tmp
# 0755 12 root root  usr
# 0755 13 root root  var
#
# ========================================================================

read -r -p "Correct file and folder permissions? [y/N] " chse
if [[ "$chse" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
    echo "Processing ..."
    #################
    # Special Cases #
    #################
    
    SDIR=("/lost+found" "/root" "/tmp")
    for sd in ${SDIR[-1]}; do
        perm=$(stat -c '%a' "$sd")
        user=$(stat -c '%U' "$sd")
        group=$(stat -c '%G' "$sd")
        if [ $sd = "/tmp" ]; then
            if [ "$perm" != 1777 ]; then
                chmod 1777 $sd
                echo "Set directory to 177 $sd"
            fi
        elif [ $sd = "/lost+found" ]; then
            if [ "$perm" != 0700 ]; then
                chmod 0700 $sd
                echo "Set directory to 0700 $sd"
            fi
        elif [ $sd = "/root" ]; then
            if [ "$perm" != 744 ];then
                chmod 744 $sd
                echo "Set directory to 744 $sd"
            fi
        else
            echo "Abort!"
        fi
        # Do change in ownership
        if [ "$user" != root ]; then
            chown root $sd
            echo "Set user to root $sd"
        fi
        if [ "$group" != root ]; then
            chgrp root $sd
            echo "Set group to root $sd"
        fi
    done
    ###############
    # Directories #
    ###############
    DIR=("/bin" "/boot" "/dev" "/etc" "/home" "/lib" "/media" "/mnt" "/opt" "/sbin" "/share" "/srv" "/sys" "/usr" "/var")
    for pd in ${DIR[-1]}; do
        perm=$(stat -c '%a' "$pd")
        user=$(stat -c '%U' "$pd")
        group=$(stat -c '%G' "$pd")
        if [ "$perm" != 755 ]; then
            chmod 755 $pd
            echo "Set directory to 755 $pd"
        fi
        if [ "$user" != root ]; then
            chown root $pd
            echo "Set user to root $pd"
        fi
        if [ "$group" != root ]; then
            chgrp root $pd
            echo "Set group to root $pd"
        fi

        ############################
        # Subdirectories and files #
        ############################
        # chmod directories to 755
        find -H $pd -type d -exec chmod 0755 {} \;
        # Check library files
        find -H $pd -type f \( -iname '*.so.*' -o -iname '*.so' \) -exec chmod 0644 {} \;
    done
        
    #------#
    # libs #
    #------#
    # Assign Variables
    LIBFILES=$(find -H "$(pwd)" -type f ! \( -iname '*.so.*' -o -iname '*.so' -o -iname '*.bak' \) -printf '%p\n')
    # Now do the hustle
    for PLF in $LIBFILES; do
        tstbin=$(readelf -l "$PLF" 2>/dev/null | grep -Pio 'executable|shared')
        if [ -z "$tstbin" ]; then
            tstbat=$(cat "$PLF" | head -c2 | grep -io '#!')
            if [ -n "$tstbat" ]; then
                perm=$(stat -c '%a' "$PLF")
                if [ "$perm" != "755" ]; then
                    chmod 755 $PLF
                    echo "Set script 755 $PLF"
                    # set batch to 755
                fi
            else
                perm=$(stat -c '%a' "$PLF")
                if [ "$perm" != "644" ]; then
                    chmod 644 $PLF
                    echo "Set regular 644 $PLF"
                    # set regular files to 644
                fi
            fi
            # above aren't elf binary
        else
            perm=$(stat -c '%a' "$PLF")
            if [ "$perm" != "755" ]; then
                chmod 755 $PLF
                echo "Set binary 755 $PLF"
                # set elf binaries to 755
            fi
        fi
    done
    unset IFS
    # process linux permissions for files and folders
else
    # When shit goes pear shaped
    echo "Aborted."
fi

还有其他方法可以做到这一点,也有更好的方法来编写代码。但是,它现在有效。

--->Yet another update<---

我修复了脚本中的一个粗心错误,正确地重新定位了以前由于脚本结构而无法访问的几个变量的位置。

请使用此链接获取此脚本的最新版本。

scripting debian bash permissions kali-linux
  • 1 个回答
  • 245 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve