{"id":73,"date":"2013-06-18T11:21:14","date_gmt":"2013-06-18T11:21:14","guid":{"rendered":"https:\/\/blogs.ua.es\/jpm33\/?p=73"},"modified":"2013-06-18T11:25:25","modified_gmt":"2013-06-18T11:25:25","slug":"sudo-ejecutar-comandos-con-privilegios-de-root","status":"publish","type":"post","link":"https:\/\/blogs.ua.es\/jpm33\/2013\/06\/18\/sudo-ejecutar-comandos-con-privilegios-de-root\/","title":{"rendered":"sudo: ejecutar comandos con privilegios de root"},"content":{"rendered":"<h1>Introducci\u00f3n<\/h1>\n<p>El comando <strong>sudo<\/strong> permite ejecutar un comando como el administrador del sistema (<strong>root<\/strong>). Este sistema es de uso obligatorio en Ubuntu o MacOS si se quiere realizar alguna tarea de administrador (apt-get, &#8230;). Resulta muy c\u00f3moda y &#8220;segura&#8221; ya que para realizar ciertas tareas simples de instalaci\u00f3n\/actualizaci\u00f3n del sistema no necesitamos arrancar un shell como root.<\/p>\n<p>Mi distribuci\u00f3n es Debian y en esta distro por defecto existe el usuario root y el usuario que se de de alta durante la instalaci\u00f3n. Si queremos instalar un paquete, modificar el grub, o cualquier proceso que necesite privilegios de root necesitamos arrancar un shell como root o iniciar sesi\u00f3n como \u00e9l. Si no somos expertos adem\u00e1s de incomodo puede ser &#8220;peligroso&#8221;. Por eso configurar nuestro usuario con permisos para usar sudo puede resultar muy interesante.<\/p>\n<h1>Permitir el uso de sudo<\/h1>\n<p>En primer lugar (en mi caso, en Debian) arrancaremos un shell como root y ejecutaremos el comando:<\/p>\n<pre># visudo<\/pre>\n<p>Este comando nos abre (con el editor por defecto: vi, nano, emacs) el fichero <strong>\/etc\/surdoers<\/strong> que por seguridad tiene los siguientes permisos:<\/p>\n<pre>$ ls -lh \/etc\/sudoers\r\n-r--r----- 1 root root 723 jun 1 2012 \/etc\/sudoers<\/pre>\n<p>El comando <strong>visudo<\/strong>\u00a0cambia los permisos y abre un editor con el fichero <strong>sudoers<\/strong>, pero adem\u00e1s comprueba la integridad del mismo para evitar conflictos en el sistema. Hay que tener en cuenta que es un fichero &#8220;critico&#8221;. En mi caso el fichero sudoers es algo as\u00ed:<\/p>\n<pre>#\r\n# This file MUST be edited with the 'visudo' command as root.\r\n#\r\n# Please consider adding local content in \/etc\/sudoers.d\/ instead of\r\n# directly modifying this file.\r\n#\r\n# See the man page for details on how to write a sudoers file.\r\n#\r\nDefaults        env_reset\r\nDefaults        secure_path=\"\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin\"\r\n\r\n# Host alias specification\r\n# User alias specification\r\n# Cmnd alias specification\r\n\r\n# User privilege specification\r\nmiusuario    ALL=(ALL:ALL) ALL\r\n\r\n# Members of the admin group may gain root privileges\r\n%admin ALL=(ALL) ALL\r\n\r\n# Allow members of group sudo to execute any command\r\n%sudo   ALL=(ALL:ALL) ALL\r\n\r\n# See sudoers(5) for more information on \"#include\" directives:\r\n\r\n#includedir \/etc\/sudoers.d<\/pre>\n<p>Una vez guardado, nuestro usuario ya tendr\u00eda privilegios de <strong>root<\/strong> y puede realizar cualquier tarea de administrador anteponiendo la palabra <strong>sudo<\/strong>. Por ejemplo, editar el fichero de fuentes para apt (la primera vez que ejecutemos sudo nos mostrar\u00e1 un mensaje como este, recordando que un gran poder conlleva una gran responsabilidad).<\/p>\n<pre>$ sudo nano \/etc\/apt\/sources.lst \r\n\r\nWe trust you have received the usual lecture from the local System Administrator.\r\nIt usually boils down to these three things: \r\n\r\n   #1) Respect the privacy of others. \r\n   #2) Think before you type. \r\n   #3) With great power comes great responsibility. \r\n\r\nPassword:_<\/pre>\n<p><span style=\"color: #000000;font-weight: bold\">Referencias<\/span><\/p>\n<ol>\n<li>P\u00e1gina oficial de sudo:\u00a0<a href=\"http:\/\/www.sudo.ws\/\">http:\/\/www.sudo.ws\/<\/a><\/li>\n<li>P\u00e1gina man de sudo:\u00a0<a href=\"http:\/\/www.sudo.ws\/sudo\/sudo.man.html\">http:\/\/www.sudo.ws\/sudo\/sudo.man.html<\/a><\/li>\n<li>Sudo en Wikipedia:\u00a0<a href=\"http:\/\/es.wikipedia.org\/wiki\/Sudo\">http:\/\/es.wikipedia.org\/wiki\/Sudo<\/a><\/li>\n<li>Configuraci\u00f3n de \/etc\/sudoers:\u00a0<a href=\"http:\/\/www.rpublica.net\/sudo\/sudoers.html\">http:\/\/www.rpublica.net\/sudo\/sudoers.html<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Introducci\u00f3n El comando sudo permite ejecutar un comando como el administrador del sistema (root). Este sistema es de uso obligatorio en Ubuntu o MacOS si se quiere realizar alguna tarea de administrador (apt-get, &#8230;). Resulta muy c\u00f3moda y &#8220;segura&#8221; ya &hellip; <a href=\"https:\/\/blogs.ua.es\/jpm33\/2013\/06\/18\/sudo-ejecutar-comandos-con-privilegios-de-root\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3080,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[135],"tags":[481,236729],"class_list":["post-73","post","type-post","status-publish","format-standard","hentry","category-linux","tag-debian","tag-linux"],"_links":{"self":[{"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/posts\/73","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/users\/3080"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/comments?post=73"}],"version-history":[{"count":5,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"predecessor-version":[{"id":77,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/posts\/73\/revisions\/77"}],"wp:attachment":[{"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}