Set the time limit for SSH access on the Centos Server

Source: Internet
Author: User
Tags centos server ssh access

How do I set a time limit for SSH access? Solution:

To enable the SSH remote logon time limit, you need to set the pluggable authentication module (PAM ). The time limit module is pam_time.so.

Add this module to the following file:

/lib/security/pam_time.so

The following is an example of modifying the file:

#%PAM-1.0auth       required     pam_stack.so service=system-authauth       required     pam_nologin.soaccount    required     pam_stack.so service=system-authaccount    required     pam_time.sopassword   required     pam_stack.so service=system-authsession    required     pam_stack.so service=system-authsession    required     pam_limits.sosession    optional     pam_console.so

The remaining configuration is in the/etc/security/time. conf file. the syntax of this file is as follows:

services;ttys;users;times

Service list controlled by pam tty the virtual terminal users that enables the service use the service user time. The format of this field is date/time, and the date is usually two characters. For example, MoTuSa is Monday, Tuesday, and Wednesday. The acceptable combination of two characters is Mo Tu We Th Fr Sa Su Wk Wd Al

In addition, ALFr indicates all dates except Friday. In addition, you can add "!" to the date/time format. The prefix indicates the reverse value. The start time and stop time of the time range are separated by a horizontal line. The specific time format is also a two-character HHMM that represents the hour and minute. If the end time is smaller than the start time, the system recognizes that the end time is the next day.

Therefore, to restrict jlim from logging on via ssh from five o'clock P.M. AM to am on Monday, Wednesday, and Saturday, refer to the following example:

sshd;*;jlim;MoWeWk0800-1700

Modifications to this file will take effect when any user logs on again. Note that you should test the modification to this restriction to prevent locking users or even root users by mistake.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.