6

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.

9
  • 1
    Did you try service ssh[d] restart?
    – 41754
    Dec 12, 2013 at 14:04
  • Yes I tried ,but it says no such command Dec 12, 2013 at 14:10
  • 1
    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.
    – 41754
    Dec 12, 2013 at 14:20
  • 1
    @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 ? Dec 12, 2013 at 14:58
  • 1
    @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.
    – slm
    Dec 12, 2013 at 15:04

3 Answers 3

6

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

5
  • I tried it and mentioned in my question as well Dec 12, 2013 at 14:12
  • @RajanPathak - see updates, also include your distro in the Q.
    – slm
    Dec 12, 2013 at 14:15
  • Sorry slm but systemctl sshd.service -bash: systemctl: command not found, this is what I got Dec 12, 2013 at 14:23
  • @RajanPathak - see updates, show how to do it using kill and SIGHUP.
    – slm
    Dec 12, 2013 at 14:27
  • Thanks @slm ,your trick worked out for me.I am able to see effect of changes in sshd file. Dec 12, 2013 at 15:12
0

If you're using Ubuntu, it uses the Upstart method, so try the following:

sudo stop ssh
sudo start ssh

or 

sudo restart ssh
0

On Slackware, the way to do this is:

# /etc/rc.d/rc.sshd restart

As you're probably realizing, it really depends on your distro. But if you can't figure out what sort of system your have, and therefore how daemons are started and stopped, the comment from uprego might be your best bet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.