What are the commands to apply changes made to /etc/ssh/sshd_config?

12,865

Try:

$ sudo /etc/init.d/sshd restart

systemd

If that doesn't work and your using a distro such as Fedora/CentOS/RHEL and it's using systemd then try this:

$ systemctl sshd.service reload 

You can get all the commands that sshd.service will accept by doing this. Hit the Tab key after typing the following:

$ systemctl sshd.service 
cancel                 emergency              is-enabled             list-unit-files        reload-or-restart      start
condreload             enable                 is-failed              list-units             reload-or-try-restart  status
condrestart            exit                   isolate                load                   rescue                 stop
condstop               force-reload           kexec                  mask                   reset-failed           suspend
daemon-reexec          halt                   kill                   poweroff               restart                try-restart
daemon-reload          help                   link                   preset                 set-environment        unmask
default                hibernate              list-dependencies      reboot                 show                   unset-environment
delete                 hybrid-sleep           list-jobs              reenable               show-environment       
disable                is-active              list-sockets           reload                 snapshot               

If it's a Debian/Ubuntu system they use upstart to mange services, at least with the newer versions.

See my answer to this Q&A titled: How to “close” open ports?. I discuss your options for using upstart & systemd further in that answer.

Neither?

You could use kill to send the SIGHUP signal to the running process if none of the above are appropriate for your particular distro.

$ pkill -1 sshd

Will send signal 1 (SIGHUP) to the sshd process. If you don't have the pkill or pgrep family of commands you can use ps.

$ ps -eaf | grep sshd 1234

Then take that process ID and send it a signal using the kill command.

$ kill -1 1234

Signals

If you ever forget which ones are which you can use the kill command to find out via the -l switch.

Example

$ kill -l
 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL       5) SIGTRAP
 6) SIGABRT      7) SIGBUS       8) SIGFPE       9) SIGKILL     10) SIGUSR1
11) SIGSEGV     12) SIGUSR2     13) SIGPIPE     14) SIGALRM     15) SIGTERM
16) SIGSTKFLT   17) SIGCHLD     18) SIGCONT     19) SIGSTOP     20) SIGTSTP
21) SIGTTIN     22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO       30) SIGPWR
31) SIGSYS      34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX    

References

Share:
12,865

Related videos on Youtube

Rajan Pathak
Author by

Rajan Pathak

Updated on September 18, 2022

Comments

  • Rajan Pathak
    Rajan Pathak over 1 year

    I have made some changes to /etc/ssh/sshd file and wanted these effects should take place.
    I know I can run below command for the effects to take place.

    /etc/init.d/sshd reload
    

    But on my box I could not find /etc/init.d/sshd itself.

    So is there any other command can I run which is equivalent to

    /etc/init.d/sshd reload 
    

    Edit: I am on linux kernel 2.6.28 running on embedded development board.

    • 41754
      41754 over 10 years
      Did you try service ssh[d] restart?
    • Rajan Pathak
      Rajan Pathak over 10 years
      Yes I tried ,but it says no such command
    • 41754
      41754 over 10 years
      If you are using a custom bare and undistributed GNU/Linux system you may want to just kill sshd and reinvoke it after being found with find.
    • Rajan Pathak
      Rajan Pathak over 10 years
      @uprego your point made quite a sense ,let me try this
    • slm
      slm over 10 years
      See my updates, I show how to restart using SIGHUP via the kill cmd.
    • 41754
      41754 over 10 years
      Am actually a little bit estranged of anyone doing embedded development with a kernel version 2. If you are not in a big company with lots of inertia, you may consider moving (is probably safe) to kernel 3. You may check compatibilities and do it. I'm on something with kernel 3 together with some colleagues over SPARC and ARM without much pain.
    • Rajan Pathak
      Rajan Pathak over 10 years
      @uprego,one thing I observed I killed the sshd,pkill -1 sshd and my ssh to board is disconnected but then how come again I am able to ssh to borad without starting the sshd ?
    • slm
      slm over 10 years
      @RajanPathak - yes that's the power of the SIGHUP. You're signaling the process to "hang up" as in a phone, but as soon as it hangs up it starts it self back up. Much like on a phone when you click the receiver to get a dial tone. When you press the button you "hang up" and when you release you get a dial tone.
    • 41754
      41754 over 10 years
      @RajanPathak automate, automate, automate.
  • Rajan Pathak
    Rajan Pathak over 10 years
    I tried it and mentioned in my question as well
  • slm
    slm over 10 years
    @RajanPathak - see updates, also include your distro in the Q.
  • Rajan Pathak
    Rajan Pathak over 10 years
    Sorry slm but systemctl sshd.service -bash: systemctl: command not found, this is what I got
  • slm
    slm over 10 years
    @RajanPathak - see updates, show how to do it using kill and SIGHUP.
  • Rajan Pathak
    Rajan Pathak over 10 years
    Thanks @slm ,your trick worked out for me.I am able to see effect of changes in sshd file.