sshd system with start script detailed

Source: Internet
Author: User
Tags chmod ssh openssh server

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

}

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.