sshd系统自带启动脚本详解 - Linux系统
SSH 为 Secure Shell 的缩写。sshd服务是linux系统中最经常使用的服务之一。由于其规避了明文传送口令、内容本文及中间人攻击的安全隐患,因此经常作为远程管理系统的首选方案。虽然各个linux发行版本或多或少都会有所差异,但sshd服务一定会作为标准配置出现。
本文通过分析/etc/init.d/sshd脚本来理解linux系统是如何处理sshd服务的启动、关闭等操作的。帮助我们在理解sshd服务的同时,也能够在遇到问题时快速排查、定位。不详之处,还望见谅,希望大家能够多多提出宝贵意见。 #!/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 #以上皆为注释,可以忽略。 . /etc/rc.d/init.d/functions #"."等价于source,在这里等同于C语言中的include。讲function中函数及变量的定义导入到当前脚本的执行环境中。 # pull in sysconfig settings [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd #若/etc/sysconfig/sshd为文件,就将其内容导入到当前shell运行环境 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 $RSA1_KEY ]; then echo -n $"Generating SSH1 RSA host key: " if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then chmod 600 $RSA1_KEY chmod 644 $RSA1_KEY.pub if [ -x /sbin/restorecon ]; then /sbin/restorecon $RSA1_KEY.pub fi success $"RSA1 key generation" echo else failure $"RSA1 key generation" echo exit 1 fi fi }
(编辑:佛山站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |