SSoL–Exiting Root

I don’t think most of us need to know Linux, but if you end up managing a system, it’s good to have a little idea of how to get around. This is a short series of posts as I remember the skills I used to have back in university.

There are times you need to execute a bunch of commands as root. Rather than sudo x, sudo y, sudo z, you might just sudo –i to change to root.

For example, I often will do this:

sudo apt-get update

sudo apt-get install mssql-server

sudo systemctl start mssql-server

I could just run those as root. However, when I’m done, how do I get back to my normal user? It’s been a long time, so I had to look it up. I wrote this post so I’ll remember since I don’t use Linux daily.

2017-06-15 10_05_14-Ubuntu 64-bit SQL Server .210 - VMware Workstation

Type

Exit

That’s it.

About way0utwest

Editor, SQLServerCentral
This entry was posted in Blog and tagged , . Bookmark the permalink.

2 Responses to SSoL–Exiting Root

  1. Dave Wentzel says:

    Hey, good post. In the interest of completeness, since many SQL Server Guys will read this as they journey into SSoL/containers…can I point out a few things?:
    * on Ubuntu you can’t login as root and hence run those commands. When you install ubuntu (possibly other debian derivatives too, I’m not sure) you can only create a user account with sudoers access. There is no root
    * what you say will work just fine on centos, rhel, and the fedora derivatives. Not sure about SLES, I don’t use it.
    * To avoid the constant typing of sudo you can run
    sudo su
    which will effectively get you a root prompt in BOTH ubuntu and fedora derivatives.
    * to avoid forgetting to logout/exit from your root shell what most people do is use tmux or screen. I prefer the latter
    Here’s an example:
    You login as you but you need to do some stuff as root
    screen
    sudo su
    do whatever
    ctlA to Ctl D to disconnect
    reconnect later with screen -r
    your session even remains if you lose connectivity during a long-running process. Just reconnect with screen -r when you are ready, even pick up where you left off when you get home
    Or you can share your screen with another DBA by starting screen AFTER sudo su,
    disconnect and have the other DBA connect, sudo su, then screen -r
    I love screen
    Finally, learning “history” (bash history cmd) is the best way to remember long commands that you haven’t run for awhile. or just put the commands in /etc/motd (displays on every login) if using fedora equivalents. (The motd…message of the day…is obnoxious in ubuntu)

    Thanks for sharing Steve, SSoL is awesome. Glad you are evangelizing.

    –dave

    • way0utwest says:

      Thanks, and interesting. I’ve only tested on Ubuntu, but I did sudu su and then had to google to figure things out. I haven’t done much with SSH, but since I got Bash going with Win, I’ll likely try that, which might mean I need CTRL+a,D. Right now I’ve been in a Terminal prompt and needed to just exist back to my account.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s