calvin
calvin

Reputation: 2945

How can I `ssh root@localhost` and `su root` without password on macOS?

Before asking this question, I have searched other solutions and done the following things:

  1. ssh-keygen -t rsa and cat ~/.ssh/id_rsaK.pub >> ~/.ssh/authorized_keys
  2. Enable root account on Mac, and set password to empty
  3. su root, it prints out "Sorry", so I passwd root to a non-empty password
  4. Now su root works, but still need password. I don't want this, I want to log in without type any password(Yes, it is not neat, I will check how to improve this later)
  5. ssh root@localhost fails with the following
    ssh root@localhost
    Password:
    Password:
    Password:
    root@localhost's password: 
    Permission denied, please try again.
    root@localhost's password: 
    Received disconnect from ::1 port 22:2: Too many authentication failures
    Disconnected from ::1 port 22
    

Upvotes: 0

Views: 2296

Answers (1)

dreamlax
dreamlax

Reputation: 95355

You need to put your public key into root's authorised keys. Then you should be able to ssh root@localhost without a password.

For example (make sure root has a password first):

ssh-copy-id root@localhost
# <enter root's password>

ssh root@localhost
# should log in without password
# (unless your private key is password protected, in which case, it will
# still ask for that one)

Keep in mind, some setups of SSH server forbid logging in as root. Check the /etc/ssh/sshd_config file and make sure PermitRootLogin is set to yes. If it's not listed anywhere in the file, just add PermitRootLogin yes on a line by itself (typically, anywhere in this file will do).

Upvotes: 1

Related Questions