linux shell 怎么退出

linux shell 怎么退出,第1张

不同的进入方法退出方法也不一样。

使用su root的退出方法:

输入su 用户名,回车。

输入此用户密码,回车即可切换回此用户。

使用sudo -i的退出方法:

输入exit回车,退出即可。

如果运行了其它需要退出的命令,可能要输入多次exit依次退出。

直接使用logout也可以退出。

1、首先,连接相应linux主机,进入到linux命令行状态下,等待输入shell指令。

2、执行./lua文件进入命令 *** 作模式后,按ESC,输入::q!。

3、键盘按“回车键”运行shell指令,此时会发现成功退出了文件的命令行 *** 作界面。

Linux系统虽然比Windows系统安全很多,是很好的程序开发环境,但多少还是存在一些安全隐患的。在Linux用户退出系统后,还是会有多个IP登录的风险,那么Linux退出后要如何限制IP登录Shell脚本呢?下面小编介绍一些实例。

生产环境中,有可能会出现被其他管理员或使用者修改hosts.allow允许更多的ip登陆机器为了方便统一管理,我们可以在用户退出的时候统一修改allow和deny文件成默认设置。同时也能自动获取机器所配ip的整个ip段为允许登陆。

test -f /root/.bash_logout &&chattr -i /root/.bash_logout

cat 》/root/.bash_logout 《《EOF

export TERM=xterm

/usr/bin/chattr -i /etc/hosts.allow /etc/hosts.deny

#for hosts.deny

/bin/awk ‘BEGIN{FS=“[=。]”RS=“n”}/^IPADDR/{print “sshd:all EXCEPT ”$2“。”$3“。”$4“.0/255.255.255.0”}’ /etc/sysconfig/network-scripts/ifcfg-* | grep -v 127.0.0 | uniq 1》/etc/hosts.deny

/bin/cat 》》/etc/hosts.deny 《《 iEOF

sshd:all EXCEPT ip

iEOF

#for hosts.allow

/bin/awk ‘BEGIN{FS=“[=。]”RS=“n”}/^IPADDR/{print “sshd:”$2“。”$3“。”$4“.0/255.255.255.0”}’ /etc/sysconfig/network-scripts/ifcfg-* | grep -v 127.0.0 | uniq 1》/etc/hosts.allow

/bin/cat 》》/etc/hosts.allow 《《 iEOF

sshd:ip(www.111cn.net)

iEOF

/usr/bin/chattr +i /etc/hosts.allow /etc/hosts.deny

clear

EOF

sh /root/.bash_logout 2》&1 》/dev/null

例子

这个只是检测有非法ip登录到服务器上就自动给运维报警,当然也可以改成短信报警,前提是你有短信网关。

#!/bin/bash

#该脚本作用是检测是否有恶意IP登陆服务器并邮件报警

#可以结合139邮箱以达到短信及时通知到手机的功能

#适用系统centos5

Ldate=`which date`

Lawk=`which awk`

Llast=`which last`

Lgrep=`which grep`

Lsendmail=`which sendmail`

Lifconfig=`which ifconfig`

serverip=`$Lifconfig eth0|$Lgrep inet|$Lawk -F : ‘{print $2}’|$Lawk ‘{print $1}’`

cutdate=`$Ldate |$Lawk ‘{print $1“ ”$2“ ”$3}’`

hackerip=`$Llast|$Lgrep “$cutdate”|$Lawk ‘{print $3}’|$Lgrep -v 192.168.1x.xx`

if [ -z $hackerip ]

then

exit

else

for logip in $hackerip

do

echo “hacker ip is $logip already login $serverip”|mail -s “SOS” rocdk890@139.com

done

fi


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/8674080.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-19
下一篇2023-04-19

发表评论

登录后才能评论

评论列表(0条)

    保存