Ubuntu设置sshd开机自启动

1、在/etc/init.d 下创建S99sshd文件

#! /bin/sh
DESC="sshd"
NAME=sshd
DAEMON=/user/sbin/$NAME

sshd=/bin/sshd
test -x "$DAEMON" || exit 0
case "$1" in
  start)
    echo -n "Starting $DESC:"
#    /sbin/start-stop-daemon -S -x $sshd > /dev/null
    /sbin/start-stop-daemon --start --quiet --exec $DAEMON -b
    echo "done."
    ;;
  stop)
    echo -n "Stopping $DESC:"
#    /sbin/start-stop-daemon -K -x $sshd > /dev/null
    /sbin/start-stop-daemon --stop --quiet --pidfile /var/run/sshd.pid
	  echo "done."
    ;;
  restart)
    $0 stop
    echo -n "Waiting for $DESC to die off"
    for i in 1 2 3 ;
    do
        sleep 1
        echo -n "."
    done
    echo ""
	  $0 start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac
exit 0

2、创建软连接

ln -s /etc/init.d/S99sshd /etc/rc3.d/S30sshd

3、打开rc.local文件

sudo gedit /etc/rc.local

4、添加下面命令于 exit0 之前

sudo /etc/rc3.d/S30sshd restart
exit 0

5、重启开机查看服务

ps -A

Ubuntu设置sshd开机自启动_第1张图片

6、或查找进程

ps -e | grep sshd

Ubuntu设置sshd开机自启动_第2张图片

你可能感兴趣的:(sshd,ubuntu,linux)