<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ubuntu Tutorials &#187; shell</title>
	<atom:link href="http://ubuntu-tutorials.com/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://ubuntu-tutorials.com</link>
	<description>Enhancing your Ubuntu experience!</description>
	<lastBuildDate>Sat, 28 Jan 2012 20:08:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A Root Shell On Ubuntu : The Right Way</title>
		<link>http://ubuntu-tutorials.com/2008/05/09/a-root-shell-on-ubuntu-the-right-way/</link>
		<comments>http://ubuntu-tutorials.com/2008/05/09/a-root-shell-on-ubuntu-the-right-way/#comments</comments>
		<pubDate>Fri, 09 May 2008 13:58:27 +0000</pubDate>
		<dc:creator>Christer Edwards</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[sudo]]></category>

		<guid isPermaLink="false">http://ubuntu-tutorials.com/?p=637</guid>
		<description><![CDATA[Just the other day we were having a discussion on using the root shell in Ubuntu.  Now, remember, the root user account is disabled with no assigned password on a default Ubuntu system so administrative tasks need to be done using the sudo command.  For nearly all of the administration you would need sudo will [...]]]></description>
			<content:encoded><![CDATA[<p>Just the other day we were having a discussion on using the root shell in Ubuntu.  Now, remember, the root user account is disabled with no assigned password on a default Ubuntu system so administrative tasks need to be done using the <code>sudo</code> command.  For nearly all of the administration you would need <code>sudo</code> will be adequate.  There are occasionally those fringe cases where you might require a root shell.  Below I have a few alternatives and then, if you must, the correct way of opening a root shell.</p>
<p>For more information please see the <a title="RootSudo information" href="https://help.ubuntu.com/community/RootSudo">RootSudo</a> page on the Ubuntu Community Wiki.</p>
<p><strong>Alternatives To A Root Shell<br />
</strong></p>
<p>One of the most common reasons that a user might need a root shell is due to output redirection not working as expecting while using sudo.  This can be bypassed fairly easily.  Let me outline an example:</p>
<blockquote><p><code><tt>sudo echo "foo" &gt; /root/somefile</tt></code></p></blockquote>
<p>The above example will not work because the normal user does not have access to write to the root user home directory, and combining the redirection in the command we&#8217;ve lost sudo access.</p>
<p>An alternative that <em>will</em> work would look something like this:</p>
<blockquote><p><code>echo "foo" | sudo tee /root/somefile</code></p></blockquote>
<p>This will echo the output on the console but the tee command (<code>'man tee</code>&#8216; for more information) will also take that output and write it to the file as expected.  Also note that <code>'tee -a'</code> will work in the same fashion as <code>&gt;&gt;, appending the data to the current file vs overwriting</code>.</p>
<p><strong>The Proper Way To A Root Shell</strong></p>
<p>If you still need a root shell (perhaps you&#8217;ve come across a different scenario? perhaps you&#8217;re just lazy? perhaps you&#8217;re coming from another distribution?) let me outline the proper way to gain a root shell.</p>
<p><em>DISCLAIMER: This should be avoided if at all possible.  It is not suggested to run a root shell on an Ubuntu system.  Use at your own risk.  See examples above, etc.</em></p>
<blockquote><p><code>sudo -i</code></p></blockquote>
<p>The command sudo -i is the equivalent to the <code>'su -'</code> command.  This will properly change to the root user, switch to the root user&#8217;s home directory, use his (her?) environment values, etc.</p>
<blockquote><p><code>sudo -s</code></p></blockquote>
<p>The command sudo -s is the equivalent to the <code>'su'</code> command.  This will change to the root user but will <em>not</em> properly use his (her?) environment values, etc.</p>
<p><strong>The WRONG Way To A Root Shell</strong></p>
<p>Please <strong>DO NOT</strong> use the following methods to gain root access:</p>
<blockquote><p><code>sudo bash, sudo sh, sudo su -, sudo su, sudo -i -u root</code></p></blockquote>
<p>If you currently do use these methods this post was written for you!</p>
<p><strong>UPDATE: Based on the feedback in the comments for this post I&#8217;ll try to expand the reasoning on *why* the right way is the preferred way.</strong></p>
<p>First of all we need to understand some background information.  When a user creates a session there are a number of environment values that are set.  To have a look at some of these try this command:</p>
<blockquote><p><code>env</code></p></blockquote>
<p>This will output a number of details about the current working environment.  These environment values may be different for different users.  Some of the values are generated by way of the .bashrc file (assuming a bash shell, of course), the .bash_profile, etc.  Take a look at the .bashrc in your users home directory and compare it with the .bashrc in root&#8217;s home directory.</p>
<blockquote><p><code>diff -u ~/.bashrc /root/.bashrc</code></p></blockquote>
<p>You should see some differences, and this is just from one of the multiple files that are read during a proper login.</p>
<p>When creating a root shell by using &#8216;<code>sudo bash</code>&#8216; you are not incorporating the root environment properly.  You are creating a shell with root privileges but the <code>env</code> output is still that of your user.  Each user, whether unprivileged or root, should have unique environment settings to truly be that user.  This will be the case for &#8216;<code>sudo bash</code>&#8216;, &#8216;<code>sudo su</code>&#8216; and &#8216;<code>sudo sh</code>&#8216;.</p>
]]></content:encoded>
			<wfw:commentRss>http://ubuntu-tutorials.com/2008/05/09/a-root-shell-on-ubuntu-the-right-way/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: basic (User agent is rejected)
Database Caching 2/12 queries in 0.007 seconds using disk: basic
Object Caching 238/250 objects using disk: basic

Served from: ubuntu-tutorials.com @ 2012-02-09 12:18:00 -->
