GNU/Linux >> Belajar Linux >  >> Linux

CentOS / RHEL :Cara mengatur batas waktu idle sesi (batas waktu tidak aktif) untuk logout otomatis ssh

Ada dua opsi yang terkait dengan ketidakaktifan ssh di /etc/ssh/sshd_config berkas:

ClientAliveInterval
ClientAliveCountMax

Jadi nilai timeout dihitung dengan mengalikan ClientAliveInterval dengan ClientAliveCountMax.

timeout interval = ClientAliveInterval * ClientAliveCountMax

Arti dari dua parameter dapat ditemukan di halaman manual sshd_config :

# man sshd_config
     ClientAliveCountMax
             Sets the number of client alive messages (see below) which may be sent without sshd(8) receiving any messages back from the client. If this threshold is reached while client alive messages are being sent, sshd will disconnect the client, terminating the session. It is important to note that the use of client alive messages is very different from TCPKeepAlive (below). The client alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled by TCPKeepAlive is spoofable.  The client alive mechanism is valuable when the client or server depend on knowing when a connection has become inactive. The default value is 3. If ClientAliveInterval (see below) is set to 15, and ClientAliveCountMax is left at the default, unresponsive SSH clients will be disconnected after approximately 45 seconds. This option applies to protocol version 2 only.

     ClientAliveInterval
             Sets a timeout interval in seconds after which if no data has been received from the client, sshd(8) will send a message through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will not be sent to the client. This option applies to protocol version 2 only.

Ada 2 metode untuk mengonfigurasi batas waktu tidak aktif. Misalnya dalam posting ini kami akan mengonfigurasi interval logout otomatis 10 menit.

Metode 1

1.Konfigurasikan nilai batas waktu di file /etc/ssh/sshd_config dengan nilai parameter di bawah ini.

# vi /etc/ssh/sshd_config
ClientAliveInterval 5m          # 5 minutes
ClientAliveCountMax 2           # 2 times

2. Mulai ulang layanan ssh setelah menyetel nilainya.

# service sshd restart

Ini akan membuat waktu sesi habis dalam 10 menit karena nilai ClientAliveCountMax dikalikan dengan nilai ClientAliveInterval.

Metode 2

1. Anda dapat mengatur nilai ClientAliveCountMax ke 0 dan nilai ClientAliveInterval ke 10m untuk mencapai hal yang sama.

# vi /etc/ssh/sshd_config
ClientAliveInterval 10m          # 10 minutes
ClientAliveCountMax 0            # 0 times

2. Mulai ulang layanan ssh setelah menyetel nilainya.

# service sshd restart

Perbedaan antara metode 1 dan metode 2

Ada sedikit perbedaan antara kedua metode ini. Untuk metode pertama, sshd akan mengirim pesan, yang disebut Client Alive Messages di sini, melalui saluran terenkripsi untuk meminta tanggapan dari klien jika klien tidak aktif selama lima menit. Daemon sshd akan mengirim pesan-pesan ini maksimal dua kali. Jika ambang ini tercapai saat Pesan Aktif Klien sedang dikirim, sshd akan memutuskan koneksi klien.

Tetapi untuk metode kedua, sshd tidak akan mengirim pesan hidup klien dan mengakhiri sesi secara langsung jika klien tidak aktif selama 10 menit.


Linux
  1. Cara Mengkonfigurasi Port Terpisah Untuk SSH dan SFTP Di CentOS/RHEL

  2. Cara Mengubah Pengaturan Batas Waktu Default untuk Sesi Telnet di CentOS/RHEL

  3. Cara Setup Server VNC untuk Pengguna Baru di CentOS/RHEL 5

  1. CentOS/RHEL – Cara menjalankan skrip atau perintah ketika ada pengguna yang keluar dari sesi ssh

  2. CentOS / RHEL :Cara membatasi login SSH berdasarkan waktu

  3. Cara Mengatur kunci SSH untuk login ssh "tanpa kata sandi" di Linux

  1. Cara Mengatur Kunci SSH di CentOS 8

  2. Cara menonaktifkan batas waktu di ssh selama prompt login (sesi login tidak aktif) di Linux

  3. Cara Mengatur kunci SSH untuk Login SSH “tanpa kata sandi” di CentOS/RHEL