SSH is the abbreviation for Secure Shell. SSHD Service is one of the most frequently used services in Linux systems. Because it avoids the security hidden danger of transmitting the password, content and the middle person attack, it is often the preferred scheme of the remote Management system. Although different Linux distributions are more or less different, the SSHD service will certainly appear as a standard configuration.
This article analyzes the/etc/init.d/sshd script to understand how the Linux system handles the operation of sshd service startup, shutdown and so on. Help us to understand the sshd service at the same time, can also be in trouble when the rapid investigation, positioning. The unknown, but also hope that you forgive me, we would like to make a lot of valuable comments.
#!/bin/bash
#
# Init file for OpenSSH server daemon
#
# chkconfig:2345 55 25
# DESCRIPTION:OPENSSH Server Daemon
#
# processname:sshd
# config:/etc/ssh/ssh_host_key
# config:/etc/ssh/ssh_host_key.pub
# config:/etc/ssh/ssh_random_seed
# config:/etc/ssh/sshd_config
# Pidfile:/var/run/sshd.pid
# source Function Library
#以上皆为注释, can be ignored.
. /etc/rc.d/init.d/functions
#"." Equivalent to source, which is equivalent to include in the C language. The definition of functions and variables in the function is imported into the execution environment of the current script.
# Pull in Sysconfig settings
[-f/etc/sysconfig/sshd] &&. /etc/sysconfig/sshd
#若/etc/sysconfig/sshd as a file, import its contents into the current Shell runtime environment
Retval=0
Prog= "Sshd"
Keygen=/usr/bin/ssh-keygen
Sshd=/usr/sbin/sshd
Rsa1_key=/etc/ssh/ssh_host_key
Rsa_key=/etc/ssh/ssh_host_rsa_key
Dsa_key=/etc/ssh/ssh_host_dsa_key
Pid_file=/var/run/sshd.pid
#定义变量
Do_rsa1_keygen () {#定义函数
If [!-s $RSA 1_key]; Then
Echo-n $ "Generating SSH1 RSA host key:"
If $KEYGEN-Q-t rsa1-f $RSA 1_key-c ' n ' >&/dev/null; Then
chmod $RSA 1_key
chmod 644 $RSA 1_key.pub
if [-x/sbin/restorecon]; Then
/sbin/restorecon $RSA 1_key.pub
Fi
Success $ "RSA1 Key generation"
Echo
Else
Failure $ "RSA1 key generation"
Echo
Exit 1
Fi
Fi
}