Permission denied when I tried to create a folder in root

43,271

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.

Share:
43,271

Related videos on Youtube

Lau
Author by

Lau

Updated on September 18, 2022

Comments

  • Lau
    Lau over 1 year

    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
      phemmer about 7 years
      Are you running as root when you try to execute the command? Are you using anything like SELinux?
    • Lau
      Lau about 7 years
      Yes, I'm in root folder when I try to run the command and I use ubuntu 14.04 @Patrick
    • phemmer
      phemmer about 7 years
      No, not in root folder, are you the root user (or using sudo)?
    • phemmer
      phemmer about 7 years
      @Lau If you're using sudo, please show that in your command. We need to see exactly what you're doing.
  • Kusalananda
    Kusalananda about 7 years
    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.