How do I ssh-login into my Mac as root?

3

3

For some reason I can't login as root into my Mountain Lion 10.8.2.

I've already edited /private/etc/sshd_config file by removing the comment from

PermitRootLogin yes

and restarted Mac. Still it says "Access denied" when I try to ssh into my Mac.

I also tried going to System Preferences > Sharing > Remote Login and selecting "All users" for "Allow access for" options, but I still get "Access denied". Remote Login is already turned on.

The password I use is a valid sudoing password and is the same one that was used for editing /private/etc/sshd_config file.

The program from which I'm trying to connect to my Mac is WinSCP, which is basically a file manager, so I can't do any sudoing with it and thus really need to be root in order to have full control over my Mac's files.

Desmond Hume

Posted 2013-02-22T14:44:05.250

Reputation: 1 870

Are you sure the password is the root password? Just because it's a valid sudoer password, that doesn't mean it's the root user's password. I also think Apple requires you to enable the root user as well, have you done that? Apple. Though, I still don't see a valid reason to scp as root...

– nerdwaller – 2013-02-22T14:57:19.080

@nerdwaller It's the very same password I entered when clean-installing Mountain Lion. It's the root password without a question. – Desmond Hume – 2013-02-22T15:01:56.000

@nerdwaller And how do I enable root user? – Desmond Hume – 2013-02-22T15:02:34.313

You don't set-up a root password during install on Mountain Lion... And I gave you a link above. "By default, the root user is not enabled." Per the link I provided. – nerdwaller – 2013-02-22T15:03:16.437

Can you paste the outputof ‘ssh -v root@yourmac‘? – ott-- – 2013-02-22T15:03:36.537

@nerdwaller One of the valid reasons to use WinSCP as root would be remotely editing files and modifying contents of directories that you don't have permission on when ssh-ed as a regular user, all with a pretty convenient GUI. – Desmond Hume – 2013-02-22T15:32:14.710

Answers

7

Migrated to an answer:

Per Apple:

  By default, the root user is not enabled [in Mountain Lion].

Which means, unless you have enabled the account and set the password - you probably do not have the root user even enabled. Per the link above:

Enable the root user
   1. Choose Apple menu > System Preferences, and then click Users & Groups.
   2. Click the lock icon to unlock it, and then type an administrator name and password.
   3. In the Network Account Server section, click Join or Edit.
   4. Click Open Directory Utility.
   5. Click the lock icon to unlock it, and then enter your administrator name and password.
   6. Choose Edit > Enable Root User, and then enter a root user password in the Password and Verify fields.
 Be sure to specify a secure password.

Then you can test that it works via SSH and WinSCP.

Shorter Unix way

Open Terminal and run

sudo passwd

enter your sudoing password if needed, and then provide the password for the root account when asked.

And don't forget to add "Administrators" to the list of users allowed for remote login.

nerdwaller

Posted 2013-02-22T14:44:05.250

Reputation: 13 366

Thanks, I figured it out too, with a shorter process for root account creation though. – Desmond Hume – 2013-02-22T15:11:29.643

1@DesmondHume Didn't know your experience level, and Apple people often like the menu way (in my experience). Glad you got it working. – nerdwaller – 2013-02-22T15:33:45.137

1Let's merge the answers! – Desmond Hume – 2013-02-22T15:52:57.407

@DesmondHume - Great idea. I +1'ed yours as well. – nerdwaller – 2013-02-22T16:46:28.747

1

Ok, so what I need was to enable/create the root account. The process seems to be the same as on Linux, first run

sudo passwd

in Terminal, enter your sudoing password if needed, and then provide the password for the root account when asked.

And don't forget to add "Administrators" to the list of users allowed for remote login.

Thanks to nerdwaller for the hint.

Desmond Hume

Posted 2013-02-22T14:44:05.250

Reputation: 1 870

0

One option that I currently use with my Debian install:

  1. Use WinSCP to copy the file to a writable location (eg. your home directory)
  2. Connect via SSH using a program such as PuTTY Tray
  3. Elevate yourself to root
  4. Move/Copy file to proper location

One reason I choose PuTTY Tray over PuTTY is the extended features, such as a right-click context menu.

I know this doesn't directly answer your question, but I myself have not had any luck getting WinSCP to work the way you are asking about either.

Kruug

Posted 2013-02-22T14:44:05.250

Reputation: 5 078

And now you can use WinSCP the way you want! – Desmond Hume – 2013-02-22T15:13:29.797