SSH脚本横幅打印源然后执行
SSH script banner printing source then executing
所以我为我的 SSH 服务器创建了一个 bash 脚本横幅,非常简单。它位于 profile.d:
/etc/profile.d/ssh_banner.sh
我已将 sshd_config 文件编辑如下:
# no default banner path
Banner /etc/profile.d/ssh_banner.sh
但是,当我登录到服务器时,在执行脚本和显示输出之前,它会显示之前的脚本源;
adam@adam-ThinkPad-T470s:~$ ssh adam@<IP_ADDRESS> -p 51536
#!/bin/bash
#Colours
red="3[00;31m"
RED="3[01;31m"
green="3[00;32m"
GREEN="3[01;32m"
brown="3[00;33m"
YELLOW="3[01;33m"
blue="3[00;34m"
BLUE="3[01;34m"
purple="3[00;35m"
PURPLE="3[01;35m"
cyan="3[00;36m"
CYAN="3[01;36m"
white="3[00;37m"
WHITE="3[01;37m"
NC="3[00m"
echo -e "${WHITE}******************************************************************************"
echo -e "${WHITE}** **"
echo -e "${WHITE}** Powered By Raspbian **"
echo -e "${WHITE}** **"
echo -e "${YELLOW}******************************************************************************"
CPUMOD=$(cat /proc/cpuinfo | grep -m 1 -w 'model name' | awk -F: '{print }')
HOSTNAME=$(uname -n)
KERNEL=$(uname -r)
MEMTOTAL=$(cat /proc/meminfo | grep -m 1 -w 'MemTotal' | awk -F: '{print }')
MEMFREE=$(cat /proc/meminfo | grep -m 1 -w 'MemFree' | awk -F: '{print }')
SWAPTOTAL=$(cat /proc/meminfo | grep -m 1 -w 'SwapTotal' | awk -F: '{print }')
SWAPFREE=$(cat /proc/meminfo | grep -m 1 -w 'SwapFree' | awk -F: '{print }')
echo -e "** ${YELLOW}Unauthorised access to this network is strickly FORBIDDEN **"
echo -e "** ${YELLOW}If you havn't been given authorisation ${RED}LOGOUT IMMEDIATELY!${YELLOW} **"
echo -e "**${YELLOW} This logon has been recored **"
echo -e "${YELLOW}******************************************************************************"
echo -e ""
echo -e "${WHITE} Welcome ${YELLOW}${USER}${WHITE}"
echo -e ""
echo -e "${WHITE} Date: "`date`
echo -e ""
echo -e "${WHITE} Hostname: ${HOSTNAME}"
echo -e "${WHITE} CPU Model: ${CPUMOD}"
echo -e ""
echo -e "${WHITE} Total Memory: ${MEMTOTAL}"
echo -e "${WHITE} Free Memory: ${MEMFREE}"
echo -e ""
echo -e "${WHITE} Swap Total: ${SWAPTOTAL}"
echo -e "${WHITE} Swap Free: ${SWAPFREE}"
echo -e ""
# Reset Terminal Colour Back to Normal
echo -e "${NC}"
Last login: Wed Nov 7 12:56:47 2018 from <IP_ADDRESS>
******************************************************************************
** **
** Powered By Raspbian **
** **
******************************************************************************
** Unauthorised access to this network is strickly FORBIDDEN **
** If you havn't been given authorisation LOGOUT IMMEDIATELY! **
** This logon has been recored **
******************************************************************************
Welcome adam
Date: Wed 7 Nov 13:18:42 UTC 2018
Hostname: pi
CPU Model: ARMv7 Processor rev 4 (v7l)
Total Memory: 949448 kB
Free Memory: 781588 kB
Swap Total: 102396 kB
Swap Free: 102396 kB
adam@pi:~ $
预期的横幅在通知上次登录的行之后打印出来,
我试过将 ssh_banner.sh 放在其他目录中,这导致 ssh 只打印源代码,而没有执行输出。 /etc/profile.d 是 SSH 执行横幅的唯一目录。
我不明白为什么会这样,如果有人能提供帮助,我将不胜感激。
sshd
不会执行或获取您的横幅 ssh_banner.sh
,如文档所述:
Banner
The contents of the specified file are sent to the remote user before authentication is allowed. If the argument is “none” then no banner is displayed. This option is only available for protocol version 2. By default, no banner is displayed.
如果您将横幅 ssh_banner.sh
放在 /etc/profile.d
下,则横幅是通过正常登录过程获取的,与 sshd
.
无关
所以你可以在 sshd_config
的 Banner 行前面加上注释 #
并且 ssh_banner.sh
在正常登录下仍然是来源。
所以我为我的 SSH 服务器创建了一个 bash 脚本横幅,非常简单。它位于 profile.d:
/etc/profile.d/ssh_banner.sh
我已将 sshd_config 文件编辑如下:
# no default banner path
Banner /etc/profile.d/ssh_banner.sh
但是,当我登录到服务器时,在执行脚本和显示输出之前,它会显示之前的脚本源;
adam@adam-ThinkPad-T470s:~$ ssh adam@<IP_ADDRESS> -p 51536
#!/bin/bash
#Colours
red="3[00;31m"
RED="3[01;31m"
green="3[00;32m"
GREEN="3[01;32m"
brown="3[00;33m"
YELLOW="3[01;33m"
blue="3[00;34m"
BLUE="3[01;34m"
purple="3[00;35m"
PURPLE="3[01;35m"
cyan="3[00;36m"
CYAN="3[01;36m"
white="3[00;37m"
WHITE="3[01;37m"
NC="3[00m"
echo -e "${WHITE}******************************************************************************"
echo -e "${WHITE}** **"
echo -e "${WHITE}** Powered By Raspbian **"
echo -e "${WHITE}** **"
echo -e "${YELLOW}******************************************************************************"
CPUMOD=$(cat /proc/cpuinfo | grep -m 1 -w 'model name' | awk -F: '{print }')
HOSTNAME=$(uname -n)
KERNEL=$(uname -r)
MEMTOTAL=$(cat /proc/meminfo | grep -m 1 -w 'MemTotal' | awk -F: '{print }')
MEMFREE=$(cat /proc/meminfo | grep -m 1 -w 'MemFree' | awk -F: '{print }')
SWAPTOTAL=$(cat /proc/meminfo | grep -m 1 -w 'SwapTotal' | awk -F: '{print }')
SWAPFREE=$(cat /proc/meminfo | grep -m 1 -w 'SwapFree' | awk -F: '{print }')
echo -e "** ${YELLOW}Unauthorised access to this network is strickly FORBIDDEN **"
echo -e "** ${YELLOW}If you havn't been given authorisation ${RED}LOGOUT IMMEDIATELY!${YELLOW} **"
echo -e "**${YELLOW} This logon has been recored **"
echo -e "${YELLOW}******************************************************************************"
echo -e ""
echo -e "${WHITE} Welcome ${YELLOW}${USER}${WHITE}"
echo -e ""
echo -e "${WHITE} Date: "`date`
echo -e ""
echo -e "${WHITE} Hostname: ${HOSTNAME}"
echo -e "${WHITE} CPU Model: ${CPUMOD}"
echo -e ""
echo -e "${WHITE} Total Memory: ${MEMTOTAL}"
echo -e "${WHITE} Free Memory: ${MEMFREE}"
echo -e ""
echo -e "${WHITE} Swap Total: ${SWAPTOTAL}"
echo -e "${WHITE} Swap Free: ${SWAPFREE}"
echo -e ""
# Reset Terminal Colour Back to Normal
echo -e "${NC}"
Last login: Wed Nov 7 12:56:47 2018 from <IP_ADDRESS>
******************************************************************************
** **
** Powered By Raspbian **
** **
******************************************************************************
** Unauthorised access to this network is strickly FORBIDDEN **
** If you havn't been given authorisation LOGOUT IMMEDIATELY! **
** This logon has been recored **
******************************************************************************
Welcome adam
Date: Wed 7 Nov 13:18:42 UTC 2018
Hostname: pi
CPU Model: ARMv7 Processor rev 4 (v7l)
Total Memory: 949448 kB
Free Memory: 781588 kB
Swap Total: 102396 kB
Swap Free: 102396 kB
adam@pi:~ $
预期的横幅在通知上次登录的行之后打印出来, 我试过将 ssh_banner.sh 放在其他目录中,这导致 ssh 只打印源代码,而没有执行输出。 /etc/profile.d 是 SSH 执行横幅的唯一目录。
我不明白为什么会这样,如果有人能提供帮助,我将不胜感激。
sshd
不会执行或获取您的横幅 ssh_banner.sh
,如文档所述:
Banner
The contents of the specified file are sent to the remote user before authentication is allowed. If the argument is “none” then no banner is displayed. This option is only available for protocol version 2. By default, no banner is displayed.
如果您将横幅 ssh_banner.sh
放在 /etc/profile.d
下,则横幅是通过正常登录过程获取的,与 sshd
.
所以你可以在 sshd_config
的 Banner 行前面加上注释 #
并且 ssh_banner.sh
在正常登录下仍然是来源。