Centos – sudo -i returns an error

centoscommand linelinuxsudo

When I try to switch to root using sudo -i i get the error /var/tmp/sclDvf3Vx: line 8: -i: command not found… However, su - works which I will continue to use. I'm by no means a linux system administrator so the environment is still pretty foggy to me. I guess my questions are:

  1. Why is the error being thrown?
  2. What's the difference between the two commands?
  3. Why would you use one over the other?

Update:

I'm using CentOS version: CentOS release 6.6 (Final)

Here's the output from some commands I was asked to run, in the comments below.

  • type sudo : sudo is /opt/centos/devtoolset-1.1/root/usr/bin/sudo
  • sudo -V : /var/tmp/sclIU7gkA: line 8: -V: command not found
  • grep'^root:' /etc/passwd : root:x:0:0:root:/root:/bin/bash

Update:

This was added to my non-root user's ~/.bashrc a while back because i needed C++11 support. When I comment it out, re-ssh in, I can run sudo -i just fine without any errors.

if [ "$(gcc -dumpversion)" != "4.7.2" ]; then 
  scl enable devtoolset-1.1 bash
fi

Best Answer

From the comments and your further investigations it looks like your devtoolset is modifying the PATH. Unfortunately that includes what appears to be an old or broken sudo command.

It would be worth trying to modify the devtoolset include in your .bashrc like this, and then logging back in again:

if [ "$(gcc -dumpversion)" != "4.7.2" ]; then 
  scl enable devtoolset-1.1 bash
  PATH=/usr/bin:$PATH    # We need a working sudo
fi
Related Question