When I run "sudo su" I get –bash: command not found for everything

I’m not good with command lines or servers.
But I needed to configure for work a AMI of EC2 AWS with LINUX

So I’ve installed a lot of stuff, moved a lot of stuff around and then I realized that sudo was not behaving normally. Before, when I typed sudo, I would become a root user right away. Now when I type sudo, I get the command instructions (as if I had typed –help)

[ec2-user@ip-172-31-33-121 ~]$ sudo
usage: sudo [-D level] -h | -K | -k | -V
usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u username|#uid]
usage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U username] [-u user name|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-r role] [-t type] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-r role] [-t type] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u user name|#uid] file .

To become a root user now on my server I have to type sudo su. But once I do that all the commands stop working!

[root@ip-172-31-33-121 ec2-user]# yum

bash: yum: command not found

I’ve read somewhere it could be a problem with my PATH, and I remember I did changed something on the PATH variable while doing some installations but I can’t remember exactly what and why, I think it was when I was trying to install node.js or npm, anyway I’m not sure how to restore my PATH and if that is really the problem

*I tried to restore my path, but I don’t know how it was before, so or I restored it and it isn’t the problem or I didn’t really restored it.

Output of echo $PATH:

[root@ip-172-31-33-121 ~]# echo $PATH
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/local/bin:/opt/aws/bin:/root/bin

But I’m really new with this server config stuff, I have no idea if this is right… or wrong

When I run sudo -i:

[ec2-user@ip-172-31-33-121 ~]$ sudo -i
-bash: id: command not found -bash: tty: command not found 

[root@ip-172-31-33-121 ~]# uname -a
Linux ip-172-31-33-121 3.14.44-32.39.amzn1.x86_64 #1 SMP Thu Jun 11 20:33:38 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

UPDATE

As mentioned in the answers it was verified that /usr/bin was missing from my $PATH, so I’ve added it to my $PATH, and now when I get root by sudo su
the commands are recognized, but if I get root by sudo -i they are still not recognizable, I still get the same error:

[ec2-user@ip-172-31-33-121 ~]$ sudo -i -bash: id: command not found -bash: tty: command not found – 

[root@ip-172-31-33-121 ~]# yum -bash: yum: command not found 

UPDATE 2

We’ve identified that there is something overwriting my $PATH when i restart my shell
when I reopen my shell my $PATH variable is overwritten to this:

 [root@ip-172-31-33-121 ec2-user]# echo $PATH
 /sbin:/bin:/usr/sbin:/usr/local/bin:/opt/aws/bin

So I lose the /usr/bin again.

We’ve thought changing the .bashrc would fix it, but it didn’t
this is my .bashrc now:

 # .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi   
PATH=$PATH:/usr/bin; export PATH
# User specific aliases and functions

The result of env command:

[root@ip-172-31-33-121 ec2-user]# env
LESS_TERMCAP_mb=
HOSTNAME=ip-172-31-33-121
LESS_TERMCAP_md=
LESS_TERMCAP_me=
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
EC2_AMITOOL_HOME=/opt/aws/amitools/ec2
PYTHON_INSTALL_LAYOUT=amzn
LESS_TERMCAP_ue=
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
SUDO_USER=ec2-user
EC2_HOME=/opt/aws/apitools/ec2
SUDO_UID=500
USERNAME=root
LESS_TERMCAP_us=
PATH=/sbin:/bin:/usr/sbin:/usr/local/bin:/opt/aws/bin:/usr/bin
MAIL=/var/spool/mail/ec2-user
PWD=/home/ec2-user
JAVA_HOME=/usr/lib/jvm/jre
AWS_CLOUDWATCH_HOME=/opt/aws/apitools/mon
LANG=en_US.UTF-8
SHLVL=1
SUDO_COMMAND=/bin/su
HOME=/root
AWS_PATH=/opt/aws
AWS_AUTO_SCALING_HOME=/opt/aws/apitools/as
LOGNAME=root
CVS_RSH=ssh
AWS_ELB_HOME=/opt/aws/apitools/elb
LESSOPEN=||/usr/bin/lesspipe.sh %s
AWS_RDS_HOME=/opt/aws/apitools/rds
SUDO_GID=500
LESS_TERMCAP_se=
_=/bin/env
OLDPWD=/home/ec2-user

UPDATE FINAL

By adding

PATH=$PATH:/usr/bin; 
export PATH

to the file /etc/profile, we were able to fix sudo -i for good
sudo su is still not working, but I guess I will just use sudo -i

Thanks everybody!

Asked By: Michelle Colin

||

So, finally I got the answer to your problem.

Your PATH environment variable consists of /usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/local/bin:/opt/aws/bin:/root/bin.

But, it doesn’t contain /usr/bin.

When I do which yum OR which sudo in my CentOS, the output I get is that these executables are located in /usr/bin.

So, the only way I think it’d work is when you’ll add /usr/bin to
your PATH variable.

PATH=$PATH:/usr/bin; 
export PATH

And for permanent relief from this, add this to /etc/profile in your system.

Mind it that you need superuser privileges to achieve this last step.

Answered By: Am_I_Helpful
Categories: Answers Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.