在 GUI(Active Directory 域和信任MMC 管理单元 ( domain.msc
))中,您可以为信任关系设置“其他域支持 Kerberos AES 加密”设置:
我正在寻找一种以编程方式设置此设置的方法。我已经查看了Install-ADDSDomain
PowerShell cmdlet 以及该netdom TRUST
工具,但两者似乎都不包含设置Kerberos AES 加密设置的选项。
有人可以告诉我,如何以编程方式设置此设置?
在 GUI(Active Directory 域和信任MMC 管理单元 ( domain.msc
))中,您可以为信任关系设置“其他域支持 Kerberos AES 加密”设置:
我正在寻找一种以编程方式设置此设置的方法。我已经查看了Install-ADDSDomain
PowerShell cmdlet 以及该netdom TRUST
工具,但两者似乎都不包含设置Kerberos AES 加密设置的选项。
有人可以告诉我,如何以编程方式设置此设置?
对于上下文,我有一个使用 ssh 的多台机器的基础设施。我们通过 ssh 在没有密码的机器上以 root 身份连接,感谢每台机器上的 authorized_keys 文件。我们定期在我们的基础设施中添加新机器。
有问题的是创建一个脚本:
ssh -o BatchMode=yes $machine uname -a
)Are you sure you want to continue connecting (yes/no)?
例如,因为它是与这台机器的第一个 ssh 连接),那么使用期望脚本,发送“yes”我的问题是这两个条件 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
如何自动化服务器安装?哪些基础设施/系统适合我们的需求?
我们有 10 多台物理服务器和 100 多台虚拟机,主要是 LAMP。不是太多,但也不是任何可以自己继续工作的东西。所有服务器都有 KVM 虚拟化。我们为经常修改的客户托管各种定制应用程序。因此,这不是一个需要扩展的应用程序。项目团队直接与客户和虚拟机合作,这是一项要求。
我们经常遇到的问题是重新安装虚拟机/机器会变得很棘手,因为没有人控制它们最近的更改,这会带来不稳定的风险,人们会尽可能地推迟它,并且随着时间的推移问题会变得更大。
我想至少每 3 个月根据需要建立一个重新安装程序。重新安装应从代码存储库和备份开始。这不应该是虚拟机重复。
我们估计,如果手动完成,在当前设置中每 3 个月将花费我们大约 6 个人工月。我们如何才能减少这个时间并增加过程的可重复性?
问题是什么软件可以帮助我们自动完成这项任务。它应该尽可能轻。我们不需要自动节点分配。我们只需要重新安装以尽可能自动化。我们假设每次重新安装都有人工监督。
我们的节点主要是 LAMP,有两个系统具有超过 1TB 的结构化数据库数据、几个 >200GB 和大约 50 个小型自定义 VM。我们可以轻松地安排每个系统的计划停机时间,因此这不是重新安装期间的高可用性问题。
我们只需要尽可能地自动重新安装。
esxcli
存在于vSphere
。但我需要编写脚本vCenter
并且vCenter
没有esxcli
命令。
我该如何编写脚本vCenter
?
我必须将备份从 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>
我的问题:
为什么\Program was unexpected at this time.
当我尝试时出现消息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
回显为FOR /D \Program Files\MariaDB 10.3\data\*") DO rmdir "p" /s /q
?看起来(但我不确定)它可能与“%p”变量有关。
为什么剩下的指令(导入备份、恢复 my.ini 和启动 MariaDB)没有执行?
我不得不承认,我是 Windows 脚本的新手。而且我认为没有必要为一个脚本安装完整的 Python3!
更新:我试图在“准备备份以进行恢复”之前“擦除数据库文件”,但我得到了相同的结果,即它在“FOR”指令处停止。
我的 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。包括标准错误和标准输出。
两者都有相同的结果并且工作正常,但是为什么有些人使用第一种类型而有些人使用另一种呢?
我需要编写一个脚本,以便我和我的同事可以在多台服务器上重新启动不同的服务。我们都使用 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 登录名/密码。
我不是新手。我是一名专业人士,向其他专业人士寻求快速解决常见问题的方法,我知道是什么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: <--
没有找到理想的解决方案,我已着手修改上述脚本并使其有助于我想要的解决方案:
#!/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<---
我修复了脚本中的一个粗心错误,正确地重新定位了以前由于脚本结构而无法访问的几个变量的位置。
在多台机器上运行 Fedora 33/34。我成功激活rc-local.service
了它工作正常。我有几个需要运行的其他脚本,/etc/init.d/
并且我创建了与 类似的服务文件rc-local.service
,但我无法启用它,而 rc-local.service 可以毫无问题地启用/禁用/盯着/停止。
我知道,我有一个选项(我目前使用)从rc.local
文件中调用这些脚本,但宁愿将它们作为服务单独调用。所以我的服务文件如下所示:
#cat net-scr1.service
[Unit]
Description=Network check service
ConditionFileIsExecutable=/etc/init.d/net-scr1
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/net-scr1 start
TimeoutSec=3
ExecStop=/etc/init.d/net-scr1 stop
RemainAfterExit=yes
GuessMainPID=no
StandardOutput=tty
[Install]
WantedBy=multi-user.target
systemctl enable net-scr1
Synchronizing state of net-scr1.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable net-scr1
service net-scr1 does not support chkconfig
我将脚本移出init.d
考虑可能 systemd 假设它是一个旧sysv
脚本,但没有改变。我的脚本中应该有什么才能正常工作?
我的脚本看起来像:
#!/bin/bash
[email protected]
[email protected]
dv0=p1p1
ipdv0=`ifconfig $dv0 | grep "inet " | awk '{print $2}'`
if [ "$1" = "stop" ]; then
cat $msg | mail $EMFR -s "$srv-shut_down-ip-$ipdv0" $eml
fi
if [ "$1" = "start" ]; then
cat $msg | mail $EMFR -s "$srv-booted_up-ip-$ipdv0" $eml
fi
我应该包含旧 sysv 系统中的函数还是其他什么?谢谢