homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / WebmasterWorld / Webmaster General
Forum Library, Charter, Moderators: phranque

Webmaster General Forum

[SSH] 'service sshd restart' doesn't work when logged in as non-root

10+ Year Member

Msg#: 4182173 posted 12:37 am on Aug 5, 2010 (gmt 0)

Hi there,

I am trying to harden SSH logins on a CentOS dedicated server and noticed that:

1) when I set:

PermitRootLogin no
AllowUsers thatuser

in /etc/ssh/sshd_config


2) login SSH with that non-root user and su as root (I also check that I'm root with whoami and see that i am root)

I noticed that i.e. a command like service sshd restart gives:

service sshd restart
bash: service: command not found

but /etc/init.d/sshd restart works.. that's OK, but why on earth 'service sshd restart' doesn't work?




WebmasterWorld Senior Member lammert us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Msg#: 4182173 posted 2:02 am on Aug 5, 2010 (gmt 0)

If you do a "su" command, the login scripts of the new user level are not parsed and all environment variables are inherited from the previous user. The root user needs some extra directories added to the PATH environment variable to be able to execute privileged commands.

The correct way to become root with all necessary settings is "su -" which causes the new shell to execute the login scripts for user root.


10+ Year Member

Msg#: 4182173 posted 4:39 am on Aug 5, 2010 (gmt 0)

Wow! Great! really appreciated..

Global Options:
 top home search open messages active posts  

Home / Forums Index / WebmasterWorld / Webmaster General
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved