2

I have access to a CentOS server with a user that its not root but belongs to the sudoers list. I do not have the password of root, nor I can't find out what it is (policies of the people who gave me access to the server).

I want to enable SSH login with root, meaning I don't want to keep logging in to the server with some user, and always do sudo su - in order to do about anything. So far I was able to enable SSH login with my user and a passphrase, which is nice, but I would like to be able to login directly in the root user.

Can I do this without the password of root? How? Any links/books or information would be appreciated.

I don't know if the reason why I need this is relevant to the question, but is this: I have 64 machines just like this server, and I have to install in each of them some software. In order to do this, I set up a passwordless SSH and a bash script that installs the software in each machine. The thing is, the software I need to install requires root permissions and if I include in the bash command sudo su I have to write 64 times the same password each time that command appears in the script. That's why I need to enable ssh login with root somehow.

  • 1
    Can you even use sudo su -? Normally, su - should ask you for root's password. For that matter sudo *some command* will allow you to perform maintenance tasks on the server in question. I think you need this tip over at Google Chromium that relaxes sudo – eyoung100 Nov 20 '14 at 22:37
  • @eyoung100 Yes I can use sudo su -, but it asks me for my user's password. Thanks for the link, I will check it out. – user3424545 Nov 20 '14 at 22:54
  • Then something is wrong, or your sudo configuration is non standard. sudo su asks for your password to account for sudo, but su - should ask for root's password. You aren't being asked for it because sudo is overriding it. What are you trying to do as root? – eyoung100 Nov 20 '14 at 23:00
  • @eyoung100 by the time su - is run, you are already effectively root from sudo and as such, no additional password is needed. Root can run su with no password. – casey Nov 21 '14 at 0:24
  • @eyoung100 I don't really know, but both commands ask me for my user's password. I have 64 machines just like this server, and I have to install in each of them some software. In order to do this, I set up a passwordless SSH and a bash script that installs the software in each machine. The thing is the software I need to install requires root permissions and if include in the bash command sudo su I have to write 64 times the same password each time that command appears in the script. So I need to enable ssh login with root somehow. – user3424545 Nov 21 '14 at 0:25
3

Connecting to a machine as root user is a highly discouraged practice since it obscures who is really connecting.

For example: If you look at your ssh log files, you will only see connections from one user, which makes it very difficult to track down if it is a malicious connection.
You loose the ability to ask/answer questions like "Why was bob connecting to the server at 3:30 in the morning?"

If this is a test machine, or you are willing to accept those risks, then uncomment the following line in /etc/ssh/sshd_config

PermitRootLogin yes

Then restart the ssh daemon

service sshd restart

A slightly less risky alternative would be to setup ssh keypairs (so you don't need to type in your password every time you connect). And also configure your user so that they aren't prompted for a root password every time you sudo.

  • This is a test machine. I tried your method, but doesn't work. Do I have to generate another set of keys after I change sshd_config? – user3424545 Nov 21 '14 at 0:26
  • No, try adding debugging info by adding -vv to the end of the command. Also your root user will need to have a password setup – spuder Nov 21 '14 at 5:59
2

Login by root it's not a good practice. You can configure your system to login with ssh-keys. And also disable login using password. Look at this post

And if you have root privileges you can change root password. Use this commands:

$ sudo -s 
# passwd root
  • I don't think the people who gave him permission to us sudo would appreciate him changing the root password. The other method could work, but I would not do this without permission of the owners. – switch87 Nov 20 '14 at 22:26
  • As @switch87 said I don't wnat to change the root password. Also, as I mentioned in my post I already enabled login wiht ssh-key with my user, but I would like to access directly in root. – user3424545 Nov 20 '14 at 22:58
0

Your shell is now a file that invokes 'sudo -i'

Swish.

I've done it, but I don't think that's how I did it. Try that. If it sucks, I'll think harder.

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.