LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-21-2010, 12:01 PM   #1
ytd
Member
 
Registered: Jan 2009
Posts: 205

Rep: Reputation: 31
Disable root login, but still be able to sudo -s after logged with another user (ssh)


How can I disable the root login in ssh ? I don't want to be able to log in with the root in ssh, I want to be able to log in with a specific user in ssh, and then to be able to sudo -s root and became root.
In ubuntu, the default is like this. My question is, how do I do this on a centos5 machine ? or any other generic linux server.
 
Old 04-21-2010, 12:47 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
edit /etc/ssh/sshd_config and set PermitRootLogin to no. and restart sshd
 
1 members found this post helpful.
Old 04-21-2010, 11:29 PM   #3
ytd
Member
 
Registered: Jan 2009
Posts: 205

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by acid_kewpie View Post
edit /etc/ssh/sshd_config and set PermitRootLogin to no. and restart sshd
Just like that ? As simple as that ? That's all I have to do ?
I've been looking in sshd_config, and saw the PermitRootLogin = yes, but I was thinking that I will not be able to log in then with root, after I log with a linux user.

One last thing, (I hope) after I set PermitRootLogin = no, for example, for user abc, do I need to write in sudoers, or in sshd the user that has the right to switch into the root acount (sudo -s) ?
 
Old 04-22-2010, 12:14 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
That config file is for SSH. sudo is NOT ssh, once you're logged in to the remote system, ssh is utterly irrelevant to what you do and has no idea at all how sudo is configured.
 
Old 04-22-2010, 01:21 AM   #5
ytd
Member
 
Registered: Jan 2009
Posts: 205

Original Poster
Rep: Reputation: 31
I have many different servers. One with Ubuntu 32b 9.04 one with CentOS 4 64b, one with CentOS 5, one with RH 3.0 AS, etc.

For example, on the Ubuntu 32bit V9.04 in sshd_config PermitRootLogin = yes but I still can't connect with the root through ssh. I need to connect with my user, and then I can su root. This Ubuntu has GUI.

That's why I'm asking if there isn't a config file, or something, in where I can restrict the login with the root user.

I think when I installed Ubuntu, it promted me to make a default user (not root), and I'm not sure, but... I think I have completed some steps, in which I configured the login for root user. I don't know I'm not quite sure what I did, 2 years ago.
 
Old 04-22-2010, 02:24 AM   #6
gimpy530
Member
 
Registered: Oct 2007
Posts: 98

Rep: Reputation: 16
Ubuntu does not let people log in as root by default. When I say that I mean that SSH may be configured to allow it, but by default you still can't do it. If you set root's password yourself (with passwd, see man passwd) you would be able to log in to that Ubuntu box as root, but logging in as a general user and using sudo is preferred.

The change to sshd_config will stop anyone from being able to log in remotely as the root user, but root may still be able to log on locally, except in Ubuntu and a few other distros that "disable" the root user completely, not just via SSH.
 
1 members found this post helpful.
Old 04-22-2010, 09:11 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
As above, Ubuntu is non-std in the way it handles root user.
On a std system, in Unix+Linux, acid_kewpie's answers are correct.
Ubuntu actually disables the root user locally, so the setting in sshd is ignored. Ubuntu makes the first created normal user able to run anything as root by prefixing the cmd with 'sudo'. This is not what sudo was created for.
 
1 members found this post helpful.
Old 04-22-2010, 11:44 PM   #8
ytd
Member
 
Registered: Jan 2009
Posts: 205

Original Poster
Rep: Reputation: 31
Tyvm Chrism01, you helped me alot of times.
So like... in general, the other linux distribution except ubuntu and a few others, can't and will not have this option to disable the root user, except that I can configure that in sshd and that's it ? Any other restriction file that I can edit to make the root login disabled dosen't exist in these linux distributions?

I just checked in my ubuntu linux box, I could log in with the root after I passwd from root, but I set PermitRootLogin = no :P afterall.

LE: idk why it didn't work in the first place, I did passwd from root, set the root password, and then restarted ssh (or no, hmmm idk...) and still couldn't log in with the root user. Now after I did passwd from root user, restarted ssh, I could log in with the root user, but like I said, I have disabled the PermitRootLogin from the ssh.

Last edited by ytd; 04-22-2010 at 11:46 PM.
 
Old 04-23-2010, 02:45 AM   #9
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well you can easily make root behave in the ubuntu style on other systems, just give the root account a random password and forget it. Their sudo implemented is not "interesting" they just advocate it's use a lot more than other systems by default. on Ubuntu you *can* set a root passwd if you like and start using that accont directly, but it's just not advised.
 
Old 04-24-2010, 01:12 PM   #10
ytd
Member
 
Registered: Jan 2009
Posts: 205

Original Poster
Rep: Reputation: 31
I don't think I got the point, I don't understand very well english, and I don't understand what you meant by give the root account a random password and forget it.
But, I'll leave it that way, I solved the "problem" I had, so... thankx anyway.
 
Old 04-24-2010, 04:50 PM   #11
Bratmon
Member
 
Registered: Jul 2009
Location: 75.126.162.205:80
Distribution: Arch / Mint 17
Posts: 297
Blog Entries: 3

Rep: Reputation: 50
Quote:
Originally Posted by acid_kewpie View Post
well you can easily make root behave in the ubuntu style on other systems, just give the root account a random password and forget it.
Code:
#passwd -l root
100% less chance of a brute-force guessing it.
 
1 members found this post helpful.
Old 04-25-2010, 11:01 AM   #12
ytd
Member
 
Registered: Jan 2009
Posts: 205

Original Poster
Rep: Reputation: 31
Are you serious ? I need the root password to become root!
Or, wait a minute... in fact, I can set my username in sudoers, with root privileges, and then reset the password for root with that command.
Is that what you are trying to say ?
And with that command, passwd -l root why do you say 100% less chance of a brute-force guessing it ? What is that command doing, why is that command so special in that you can't recovery the root password ? Can you be more specific ? From my opinion, I rather set a strong password, 20 characters, with case sensitive and upper case and lower case, and *#$^*#$ and I bet it's stronger than passwd -l root. Or maybe I'm wrong. Once again, why is that command so special ? Can you please tell me ? I've search the internet, and couldn't find anything about that command.
 
Old 04-25-2010, 11:34 AM   #13
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Yes, that's the logic, you never go in directly as root, which is not very auditable, only become root through another much more trackable human specific account. well the -l option "disables" the account by making the password reversibly illegal, AFAIR by putting a ! in the string, which means it will never be able to be matched.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to disable remore ssh login access of "root" user. ashishshukla Linux - General 3 10-07-2008 08:55 AM
Disable Root login via ssh UltraSoul Solaris / OpenSolaris 3 02-09-2007 02:18 AM
Disable Root Login Via SSH = Why? carlosinfl Linux - Security 4 10-11-2006 12:32 PM
disable root login with ssh linuxtesting2 Slackware 3 02-16-2005 12:33 PM
How can I disable root login with SSH? blk96gt Slackware 9 10-02-2004 07:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration