4

Hi I tried to create a folder for ssh key in root with this command:

mkdir /root/.ssh && chown -R root:root /root && chmod -R 770 /root

and I have permission denied:

mkdir: cannot create directory ‘/root/.ssh’: Permission denied
phemmer
  • 70,657
  • 19
  • 188
  • 223
Lau
  • 41
  • 1
  • 1
  • 2

2 Answers2

3

The super user has no real reason to have SSH access. It's is safer to set up an ordinary user with SSH access to the machine and then use sudo when needed. You can even set PermitRootLogin no in your sshd_config file (under /etc somewhere) unless you, for some reason, think you may need to actually log in as root to unbreak the system at some point (which you can do from the console anyway, if you have physical access to the machine).

Having said that, you are probably executing your commands as an ordinary user which is why you don't have permission to perform the operations.

Never change ownership or permissions on the /root directory though. They are correctly set up from the start and shouldn't need changing (which may open up for security holes later).

On all the systems I've set up, the original contents of /root and the directory itself is totally untouched. Nothing added, nothing taken away, nothing modified. The root account is special, and you should rarely, if ever, see an interactive root prompt.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
0

You have to switch the user to root "#su root" OR you can use the below command with sudo prefix sudo mkdir /root/.ssh && chown -R root:root /root && chmod -R 770 /root

Note: your local must be added in sudoers file.

  • 1
    Note that all parts of your second command needs `sudo` and that you shouldn't fiddle with the ownership or permissions of the `/root` directory itself, ever. – Kusalananda Apr 19 '17 at 07:17