centos登录超时(centos怎么登录)
大家好,今天小编来为大家解答以下的问题,关于centos登录超时,centos怎么登录这个很多人还不知道,现在让我们一起来看看吧!
Centos下限制SSH登录次数详解
应公司内部网站等级测评的需求,正逐渐加强系统安全防护。
设备默认 3次验证失败自动退出,并且结束会话;网络登录连接超时自动退出时间 5分钟;
第一种方法:已验证。
1.ssh超时时间设置
# cd/etc/profile.d/#创建两个空白文件autologout.csh、autologout.sh用来保存TMOUT配置
# touch autologout.csh
# touch autologout.sh
# vi autologout.sh#编辑autologout.sh
#auto out in 5 minutes
TMOUT=300#超时时间,单位为s
readonly TMOUT#设置TMOUT变量只读
export TMOUT#设置环境TMOUT
# vi autologout.csh#编辑autologout.csh
set-r autologout 2
# chmod+x autologout.*#可执行权限,其实单给u+x就行了。
断开Client,重新登录终端5分钟不使用ssh就会自动断开连接.
2.ssh认证次数限制:
/etc/ssh/sshd_config
MaxAuthTries=3这仅是超过3次验证错误断开连接。
第二种方法:(试验中还是有问题出现)
原理:通过系统的pam认证实现。
1.备份/etc/pam.d/system_auth文件,更改:
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth required pam_env.so
auth required pam_unix.so nullok try_first_pass将原来的sufficient改为required
#auth requisite pam_succeed_if.so uid>= 500 quiet注释掉此行
auth required pam_tally.so deny=3unlock_time=300增加一行,失败超过3次限制5分钟后登录
#auth required pam_deny.so注释掉此行
account required pam_unix.so
account sufficient pam_succeed_if.so uid<500 quiet
account required pam_permit.so
account required pam_tally2.so增加一行
password requisite pam_cracklib.so try_first_pass retry=3
password sufficient pam_unix.so md5 shadow nullok try_first_pass use_authtok
password required pam_deny.so
session optional pam_keyinit.so revoke
session required pam_limits.so
session [success=1default=ignore] pam_succeed_if.so service in crond quiet use_uid
session required pam_unix.so
2.建议sshtest帐户,进行密码错误登录验证。查看tail/var/log/secure|grep sshtest记录:
Feb 22 15:21:11 SN524 sshd[4900]: Failed password for sshtest from 192.168.40.130 port 53995 ssh2
Feb 22 15:21:17 SN524 sshd[4900]: pam_tally(sshd:auth): user sshtest(503) tally 7, deny 3
Feb 22 07:21:19 SN524 sshd[4903]: Disconnecting: Too many authentication failures for sshtest
Feb 22 15:21:19 SN524 sshd[4900]: Failed password for sshtest from 192.168.40.130 port 53995 ssh2
Feb 22 15:22:05 SN524 sshd[4906]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.40.130 user=sshtest
帐户已被锁住,无法登录,等待5分钟后才能重新登录.
3.限制SSH过期时间:
/etc/ssh/sshd_config
ClientAliveInterval 60
ClientAliveCountMax 60
centos7+tomcat登陆超时
在工作中开发找到说,项目日志访问域名报错,报错如下:
这是第二次遇到的报错,所以把它记录下来,在服务器curl是另外一种结果,服务器结果如下:
经过第一次的经验就知道,本机的jdk是不信任你这域名的,然后我将这个域名的私钥证书,就是.crt结尾的证书转换成.cer结尾的证书,进行导入到本机jdk里面就可以实现程序的信任了,好了话不多说操作如下。
1.拿到私钥证书之后,使用ie浏览器导入到浏览里面。
找到你的私钥证书
选择你的组
这就是导入成功了。
开始导出.cer结尾的证书,选择你导入证书的组然后点击导出来
选择你要导出的证书编码类型
选择要导出的位置以及导出证书的名字
导出完成。
得到了一个后缀为.cer结尾的证书。然后接下来导入到我们需要的服务器jdk中即可
2.liunx导入证书的命令为如下(本片文章jdk是以yum安装的jdk为主导入的):
(1)找打jdk安装的目录
# pwd
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64/jre/lib/securi
(2)上传要导入的证书
(3)进入jdk安装目录,然后进行导入证书
#导入证书命令
# keytool-import-trustcacerts-alias tomcat-file/home/cert/111.cer-keystore"/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64/jre/lib/security/cacerts"-storepass changeit
#删除证书命令
# keytool-delete-alias server-keystore D:\jdk1.6.0\jre\lib\security\cacerts-storepass changeit
这样再用程序调用这域名就不会报超时了。
Centos下为程序如何设置超时Centos下为程序设置超时的方法
timeout是个奇妙的Linux命令,它可以控制程序运行的时间,这对于我们希望控制程序的运行时间非常有用。
timeout在CentOS 6平台上,从属于软件包coreutils
# which timeout
/usr/bin/timeout
# rpm-qf/usr/bin/timeout
coreutils-8.4-19.el6_4.2.x86_64
timeout的原理很简单,一个简单的计时器,一个kill命令,其中-s可以跟kill的参数,具体怎么杀,就看它。
man timeout仅仅半页,如下
TIMEOUT(1) User Commands TIMEOUT(1)
NAME
timeout- run a commandwith a timelimit
SYNOPSIS
timeout [OPTION] NUMBER[SUFFIX] COMMAND [ARG]...
timeout [OPTION]
DESCRIPTION
Start COMMAND, and killit ifstill running after NUMBER seconds. SUFFIX may be sforseconds(the default), m forminutes, h
forhours or d fordays.
Mandatory arguments to long options are mandatory forshort options too.
-s,--signal=SIGNAL
specify the signal to be sent on timeout. SIGNAL may be a name like HUP or a number. See kill-l fora list of signals
--help display this help and exit
--version
output version information and exit
If the commandtimesout, thenexitwith status 124. Otherwise, exitwith the status of COMMAND. If no signal is specified, send the
TERM signal upon timeout. The TERM signal kills any process that does not block or catch that signal. For other processes, it may be
necessary to use the KILL(9) signal, since this signal cannot be caught.
AUTHOR
Written by Padraig Brady.
用法举例
1timeout 120 command
上面的command命令如果在120秒内完成,则平安结束,运行超过120秒后将被杀死。
脚本经常是傻乎乎的一口气跑到完,搞得我们需要写另一个脚本定期去杀它。自打有了timeout命令,腰也不疼了,腿也不酸了,跑跑歇歇更健康。
一句话,我们在脚本里或者crontab里就不用再造轮子了。