Permission denied when I tried to create a folder in root
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.
Related videos on Youtube
Lau
Updated on September 18, 2022Comments
-
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 about 7 yearsAre you running as root when you try to execute the command? Are you using anything like SELinux?
-
Lau about 7 yearsYes, I'm in root folder when I try to run the command and I use ubuntu 14.04 @Patrick
-
phemmer about 7 yearsNo, not in root folder, are you the root user (or using
sudo
)? -
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 about 7 yearsNote 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.