我有一点问题。我正在使用systemd服务(守护程序)。该脚本如下:
if [ $intento = 5 ];then
iptables -I INPUT -s ${sublista[0]} -j DROP -m comment --comment "IP bloqueada por sshield"
date=$(date)
echo "${sublista[0]} $date" >> /var/cache/sshield.deny
zenity --notification --text "IP address ${sublista[0]} denied at $date - sshield"
email [email protected] "Nueva regla iptables | ${sublista[0]} denied" "The ${sublista[0]} ip address is denied by brute force's attack ssh.<br><br>Date: $date"
declare -a ips=(${ips[@]/${sublista[0]}=>$intento/})
fi
想法如下:
如果尝试次数超过五次,则给出IP地址并将其锁定。发送邮件并显示Zenity的弹出窗口
问题是,弹出窗口不显示。
zenity --notification --text“ IP地址$ {sublista [0]}在$ date被拒绝-屏蔽”
我相信这是因为scrpt由/lib/systemd/system/sshield.service中的服务文件执行
[Unit]
Description=Service for protect attacks of brute force ssh's
[Service]
Type=simple
ExecStart=/etc/sshield/sshield.sh
ExecStop=/etc/sshield/sshield.sh stop
RemainAfterExit=yes
Restart=always
[Install]
WantedBy=multi-user.target
我相信问题出在:Type = simple
另外,我尝试这样做:
echo "${sublista[0]} $date" >> /var/cache/sshield.deny
sshield --bell "IP address ${sublista[0]} denied at $date - sshield"
email [email protected] "Nueva regla iptables | ${sublista[0]} denied" "The ${sublista[0]} ip address is denied by brute force's attack ssh.<br><br>Date: $date"
sshield --bell“在$ date拒绝IP地址$ {sublista [0]}-sshield”
命令
sshield
是路径/bin/sshield
中的脚本,我可以遵循它:elif [[ $argumento == "--bell" ]];then
if [[ $# -gt 3 ]];then
echo -e "\033[1;31m[-]\033[0m Only one value"
echo "You use '--help' or '-h' for more information"
elif [[ $# = 1 ]];then
echo -e "\033[1;31m[-]\033[0m It needs one value"
echo "You use '--help' or '-h' for more information"
else
zenity --notification --text "$2"
fi
else
[...]
标记:zenity --notification --text“ $ 2”
但是,它不起作用。我该如何解决?
错误在于善意:
image: journalctl -u sshield
最佳答案
用于在服务(系统化)中执行GUI(图形用户界面)。首先,您必须添加以下内容:
[Service]
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/ivan/.Xauthority"
结果:
[Unit]
Description=Service for protect attacks of brute force ssh's
[Service]
Type=simple
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/ivan/.Xauthority"
ExecStart=/etc/sshield/sshield.sh
ExecStop=/etc/sshield/sshield.sh stop
RemainAfterExit=yes
Restart=always
[Install]
WantedBy=multi-user.target
然后在脚本中添加:
export DISPLAY=":0"