I was reading the following code:
$ sudo bash # cd /home/ # ./gitpull.sh
Why do I need the first line, what does it do exactly? What if I just did
$ sudo instead of
$ sudo bash ?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
sudo <shell>, if it works, betrays a poor installation of sudo and a potential security weakness.
sudo should not be configured to allow arbitrary commands like shell; the purpose of
sudo is to allow authenticated non-root users to run certain commands as root, without knowing the root password.
sudo bash is allowed to any user, that user is root simply by virtue of knowing his own password.
If an attacker obtains the password of any one of the accounts which are able to do
sudo bash, the attacker thereby has root.
The proper way to do the equivalent of
sudo bash (obtain a root shell) is
su, followed by giving the root password, not your own.
The infamous sudo is an acronym of sorts for Superuser Do.
It basically make a normal user a Super user for a short while.
In your command sudo bash , effectively you are saying Superuser do --> a Bourne shell ( bash ) Which opens a root user logged in shell.
If you just ran sudo the operating system wouldn't know what to do. So in general sudo is followed by a unix command.
sudo bash instead of
sudo is specified to
./gitpull.shfrom bash and not another shell such as
pdkshor plain old
sh. I'm pretty sure the script's hashbang line should allow the script to specify what shell to run it under but maybe it was omitted for some reason or the instruction writer doesn't want you to rely on that.
bashwithout other arguments it doesn't act like a "login shell" and maybe the script depends on that.
Also @nisdis is right. Plain old
sudo just prints usage information. But why not use