I am playing around with Linux, and am starting out with using the terminal. I am trying to create folders on the root of the filesystem, which my regular user does not have permissions to do.

When running su root mkdir u01; I am prompted for credentials, and then Terminal returns the error "Cannot execute binary file"

If I run su root and then mkdir u01, the command works fine.

Any ideas?

I am on Oracle Linux 6.5

  • maybe the user who you try to execute the command through hasn't sufficient credentials to do so ! – wisdom Jul 5 '14 at 12:39
  • What is your default shell for root? What is the output of locate mkdir? I am asking because in one case you might be trying to run a binary called mkdir and in the su case you might be using a shell internal command. – Hennes Jul 5 '14 at 13:06
  • Not asked, but consider creating these folders on /usr/local/. That is probably a local partition which should remain intact if you ever need to reinstall the OS. See man hier – Hennes Jul 5 '14 at 13:07
  • I'm running a VM test environment, regularly snapshotted, so screwing up is no biggie. Using /u01 /u02 etc is the norm within Oracle systems, which is why I needed to create that folder. – razumny Jul 6 '14 at 12:43
up vote 7 down vote accepted

The problem is your call to su.

The correct syntax for executing a command as another user is:

su [username] -c "[command]"

Note the quotes around the command; its important to keep the other arguments to the command get executed properly.

  • When I try that, I hit a new roadblock: terminal returns mkdir: missing operand. The command I run is: su root -c mkdir u03 – razumny Jul 6 '14 at 18:39
  • 1
    @razumny You should type su root -c 'mkdir u03' The apostrophes are part of the command, you must type them. – MariusMatutiae Jul 6 '14 at 20:03
  • 1
    Yes, the quotes are important. I'll update my answer to include this. – ethanwu10 Jul 6 '14 at 20:05
  • That explains it, then, thanks! – razumny Jul 7 '14 at 6:28

Overall, a "normal" user shouldn't be allowed to create files or folders in the root of the filesystem. Allowing it leads to all manner of security issues.

When you run "su root mkdir u01", your system is asking you for the root password. What you probably should be running is "sudo mkdir u01" which will ask you for your normal user password. Note that this assumes that sudo is properly configured to allow this.

  • Why would you -1 my answer. I'd assumed that you'd already read the man page for su and saw the "-c" switch. My answer is correct. If it's not the one that you like, a more polite response would have been to leave it at 0. – joat Jul 5 '14 at 21:36

If you have sudo properly configured, this is proper way to create that directory:

sudo mkdir u01

If sudo does not work for some reason (or not even installed - unlikely, but possible), you can use su with command parameter -c, like this:

su -c "mkdir u01"

(note that command must be quoted to be passed properly to su).

Important difference between using sudo vs su: when prompted for password, sudo needs your user account password, but su needs root account password. On many Linux distros (notably Ubuntu/Debian family) root account password may not even be ever assigned, so su may fail (unless you assign password to root account beforehand).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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