What does `!!` mean in `sudo !!`?

1

There are two parts to the answer: !! and sudo

!! is part of the functionality of the shell (in the case of Ubuntu this is probably bash, but other shells like zsh or csh support this, too) called "history expansion". It behaves in a similar way as other expansions in that the shell expands the 'placeholder' to a set of words. While foo* would be expanded to a list of all files starting with 'foo', !! gets expanded to the contents of the previous command line.

$ echo foobar foobar $ echo !! echo foobar $ !! echo foobar

Like other expansions, this is done entirely by the shell, so if you type !! after some other command, this command is not aware that there was a !!, but will only see the previous command line. (Unlike other expansions, history expansion happens before a command is saved in the history, that is instead of !! the replaced command line will be saved to the history.)

The sudo command allows executing commands as another user, provided the...

0 0
2

Question

I have a linux-mint VM that is sitting behind a proxy. I have been trying to install vsftpd using the following command:

sudo apt-get install vsftpd

This gave me the error

Cannot initiate the connection to archive.ubuntu.com:80

So then I remembered somebody had once told me to use the -E flag

sudo -E apt-get install vsftpd

And this worked! Can anyone please explain what this flag means and why it should be used when you are behind a proxy?

Answer

-E preserves environment variables. Your proxy connection settings are stored in the env of the current user. If you elevate to root via sudo, those connection settings do not appear anymore to apt-get. With the option, the env variable is kept the same for both your user and root, so apt-get can see your proxy settings.

You can compare what is defined using the following commands :

$env $sudo env $sudo -E...
0 0
3

By default on most Unices, the "administrator" account, root, is to be used only sparingly. There are only two levels of administrator, or "super user", rights on a normal Unix system: You either have full control of everything, or you don't.

"Full control" includes circumventing most permission checks and to utterly mess up the system by a simple mis-typing. As an ordinary user, you can at most delete your own files only.

The older su utility is used together with the root password to assume the root identity, but may also be used to assume other users identities, or to execute single commands as them, given that you belong to the correct user group and know their passwords.

su is commonly used by the root user (on some Unix system) to start daemons (service processes) that need to run under particular user identities to protect them from accessing areas that they shouldn't have access to (typically web servers, SSH server and the like). This may be done in...

0 0
4

I have a linux-mint VM that is sitting behind a proxy. I have been trying to install vsftpd using the following command:

sudo apt-get install vsftpd

This gave me the error

Cannot initiate the connection to archive.ubuntu.com:80

So then I remembered somebody had once told me to use the -E flag

sudo -E apt-get install vsftpd

And this worked! Can anyone please explain what this flag means and why it should be used when you are behind a proxy?

-E preserves environment variables. Your proxy connection settings are stored in the env of the current user. If you elevate to root via sudo, those connection settings do not appear anymore to apt-get. With the option, the env variable is kept the same for both your user and root, so apt-get can see your proxy settings.

You can compare what is defined using the following commands :

$env $sudo env $sudo -E env

The -E option (or --preserve-env) Indicates to the security policy that the user wishes to...

0 0
5

When you run administrative applications in Linux, you use the su command to switch to the superuser (root) or you use the sudo command. Some Linux distributions enable the root user, but some do not. In the ones that don't—such as Ubuntu—sudo is the way to go.

About the Sudo Command

In Linux, Sudo— super user do—allows a system administrator to give certain users or groups of users the ability to run some or all commands as root while logging all commands and arguments.

Sudo operates on a per-command basis. It is not a replacement for the shell. Features include the ability to restrict the commands a user can run on a per-host basis, copious logging of each command to provide a clear audit trail of who did what, a configurable timeout of the sudo command, and the ability to use the same configuration file on many different machines.

Example of the Sudo Command

A standard user without administrative privileges might enter a command in Linux to...

0 0
6

Ok, let's start with the following command: (I'm going to simplify the file path to just answer for conciseness)

echo 43 > answer

As you probably know, this creates (or overwrites) the file named answer and gives it the contents 43. But how this happens is important: you type this into a shell, which opens the file answer, executes the command echo (passing it the argument 43), and then redirects the output to the file. The important part here is that the file is opened by the shell you're using, not by the command you're executing.

Anyway, this command will fail, because your shell doesn't have permissions to the file. So, let's use sudo to execute a command as root:

sudo echo 43 > answer

What will this do? The shell opens the file answer, executes the command sudo (passing it the arguments echo and 43) and redirects the output to the file. sudo will then execute the command echo as root (passing it the argument 43). Did you catch the problem? The current...

0 0
7

Sudo, the one command to rule them all. It stands for “super user do!” Pronounced like “sue dough” As a Linux system administrator or power user, it’s one of the most important commands in your arsenal. Have you ever tried to run a command in terminal only to be given “Access Denied?” Well this is the command for you! But, with great power comes great responsibility! It is much better than logging in as root, or using the su “switch user” command. Read on to see what sudo can do for you!

SUDO: What is is good for?

So what does sudo actually do? If you prefix “sudo” with any linux command, it will run that command with elevated privileges. Elevated privileges are required to perform certain administrative tasks. Someday you may wish to run a LAMP (Linux Apache MySQL PHP) server, and have to manually edit your config files. You might also have to restart or reset the Apache web server or other service daemons. You even need elevated privileges to shutdown or restart...

0 0
8

I'm running the command sudo find /var/www/html -type d -exec chmod g+s {} \; from here

It's said there that "We can set the setgid bit on every directory in our WordPress installation by typing the above command". The question is what do {} and / mean?

Running find --help gives Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec|time] [path...] [expression]...

So it seems like the above signs are somehow related to [path...] [expression], but their meaning is not clear.

If you look at the man page for find you'll see that -exec will execute the command for every single result found. It will determine the end of the command by \;

It will also insert the name of the directory found at {}. So the command above says find every directory under /var/www/html and executes chmod g+s on it.

excerpt from man page:

-exec utility [argument ...] ; True if the program named utility returns a zero value as its exit...
0 0
9

sudo

sudo is a program for Unix-like computer operating systems that allows users to run programs with the security privileges of another user. Its name is a concatenation of "su" and "do", or take action. Unlike the su command, users typically supply their own password to sudo rather than the root password. After authentication, and if the /usr/local/etc/sudoers configuration file permits the user access, then the system will invoke the requested command. The sudoers configuration file enables a huge amount of configurability, including but not limited to: enabling root commands only from the invoking terminal; not requiring a password for certain commands; requiring a password per user or group; requiring re-entry of a password every time or never requiring a password at all for a particular command line. It can also be configured to permit passing arguments or multiple commands, and even supports commands with regular expressions. In contrast to systems like polkit, sudo...

0 0