Uma introdução ao comando do sudo e a configuração arquivam

por Sukrit Dhandhania em Dezembro 29, 2008

Linux

Os usuários de Ubuntu Linux podem ser familiares com usar o comando do “sudo” em Linux. É uma característica muito útil em Linux que permite o administrador de uma máquina de Linux aos privilégios da “raiz” da concessão a um usuário ou a um grupo particular dos usuários. Pode também ser configurado de modo que este privilégio seja limitado a um ou mais comando. A equipe de Ubuntu, por exemplo, decidiu-se obstruir o usuário da raiz de entrar pelo defeito e permitir preferivelmente que os usuários usem o sudo executar tarefas administrativas. Assim se você estiver usando Ubuntu Linux, os privilégios do sudo setup de modo que você tivesse completamente privilégios da “raiz”. Vamos fazer exame de um olhar mais próximo no ajuste - acima e em configurar privilégios do sudo em sua máquina. Antes de proseguir por favor nota que você não deve tentar o seguinte em um usuário da produção. Tente por favor para fora os exemplos neste tutorial em uma máquina do teste e comece-os familiar com o sudo antes que você o tente para fora em um usuário da produção. o sudo é uma ferramenta muito poderosa e deve ser usado com cuidado extremo.

A meu conhecimento o pacote do “sudo” envía com todas as distribuições de Linux. Assim eu saltarei a instalação e saltarei em linha reta à configuração. Para este tutorial eu usarei uma máquina vermelha de Linux do chapéu. Registro em sua máquina de Linux como a raiz e funcionada o seguinte comando na linha de comando:

# visudo

O comando acima abrirá a configuração do “sudo”, em que está /etc/sudoers, usando o editor do defeito em sua máquina, que é Vim em meus. Enrole para baixo a seção onde você vê o seguinte texto:

raiz? ? ALL= (TUDO) TUDO

O breakup desta sintaxe da configuração do sudo vai como este. Você define primeiramente o usuário do `' para qual você quer setup o sudo. Vem então o hostname do `' onde o comando é permitido funcionar. Este podia ser um hostname específico ou “TODOS” como no exemplo acima. E último é o comando do `' para quais você querem dar privilégio administrativo do usuário do `'.

Para trás à configuração. Vim no scroll para baixo à linha mostrada acima e batida a letra o em seu teclado para adicionar uma linha nova. Adicione agora o seguinte texto, substituindo calvin com seu próprio username:

calvin ALL= (TUDO) TUDO

Conserve e retire a lima usando a seguinte combinação chave:

ESC: wq

Bata Retorno (entre) chave para aplicar estas instruções. Nós temos dado agora ao calvin do `do usuário' todos os privilégios administrativos usando o sudo. Open a new terminal window and log in as the user that you granted sudo privileges to. Let’s test whether the new permissions have been setup correctly by restarting the Apache web server as user ‘calvin’:

#?sudo /etc/init.d/httpd restart
Password:
Stopping httpd: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ ?OK ?]
Starting httpd: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ ?OK ?]

The system will now prompt you for a password. Enter the password for your username. And voila! The Apache web server should now restart. You can use this for any other administrative task. Granting complete privileges to a user may not always be the best of ideas. So you can limit the user to a few command with administrative privileges. Let’s say you want the user ‘calvin’ to be allowed to only restart the Apache web server. Open the sudo configuration file using the visudo command and edit the line you entered earlier to look like this:

calvin ALL=(ALL) /etc/init.d/httpd restart

Save and exit the file. Log into the terminal as the user ‘calvin’. Now try restarting Apache with sudo:

# sudo /etc/init.d/httpd restart
Password:
Stopping httpd: [ OK ]
Starting httpd: [ OK ]

Great. It works. Now try stopping the web server:

# sudo /etc/init.d/httpd stop
Password:
Sorry, user calvin is not allowed to execute ‘/etc/init.d/httpd stop’ as root on commons.

So as you can see, the user ‘calvin’ can only do what we allow him to do, nothing more. You can add multiple commands in the sudoers file separated by commas. So if you want to allow ‘calvin’ the permission to stop and restart the web server your configuration would read like this:

calvin ALL=(ALL) /etc/init.d/httpd restart,/etc/init.d/httpd stop

Now try stopping the web server, and it should work:

# sudo /etc/init.d/httpd stop
Password:
Stopping httpd: [ OK ]

Another feature of sudo that is pretty useful, particularly if you need to perform an administrative task using a shell script, is setting the sudo privilege without being prompted for a password. Remember that it may not be advisable to do this on a production machine using a username that is shared, because if the password for your username falls into the wrong hands it can spell trouble. So use this feature with caution.

Open the sudoers file and edit the line you entered earlier to look like this:

calvin ALL=(ALL) /etc/init.d/httpd restart NOPASSWD: ALL

The last part of the configuration instructs sudo to not prompt for or expect a password, and allow the user to execute the command that is assigned to it with administrative privileges. Save the file and exit from your text editor and try restart Apache:

# sudo /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]

There is a lot more customization that can be done to the sudo configuration file. We have just looked at a small segment of it. However, this ought to give you a start. Again, please use it with caution.

Related Posts:
  • How to install, setup and use Avant Window Navigator (Awn) in Ubuntu Feisty
  • How to play .rmvb files in Ubuntu
  • How to setup Virtual Hosts in Apache
  • How to set the date on your Linux machine
  • How to use your Nokia N95 as a wireless Webcam
  • Get Simple Help tutorials just like this one in your email inbox every day - for free! Just enter your email address below:

    You can always opt out of this email subscription at any time.

    { 2 trackbacks }

    Daily Digest for 2009-01-02
    01.02.09 at 4:03 pm
    Outrora, eu » Blog Archive » Links dos dias January 6th a January 12th
    01.12.09 at 9:06 am

    { 0 comments… add one now }

    Leave a Comment

    You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>