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

closed as off-topic by jasonwryan, countermode, ilkkachu, Jeff Schaller, GAD3R Apr 19 '17 at 13:28

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – jasonwryan, countermode, ilkkachu, Jeff Schaller, GAD3R
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Are you running as root when you try to execute the command? Are you using anything like SELinux? – Patrick Apr 19 '17 at 4:36
  • Yes, I'm in root folder when I try to run the command and I use ubuntu 14.04 @Patrick – Lau Apr 19 '17 at 4:38
  • 1
    No, not in root folder, are you the root user (or using sudo)? – Patrick Apr 19 '17 at 4:43
  • Can you please share the permissions currently on /root? – Tinu Apr 19 '17 at 11:07
  • @Lau If you're using sudo, please show that in your command. We need to see exactly what you're doing. – Patrick Apr 19 '17 at 12:35

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.


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 7:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.