Sep 01 2007

sudo

Tag: Essential Commands, LinuxVlogcanic @ 12:14 am

The root or superuser.

All Unix varieties are very versatile operating systems and within each of them the most powerful user is the administrator (known as the root or superuser). Root is the guy who can use the system with the most freedom and also the guy who can really screw things up when doing something wrong, and since he is enabled to erase accounts, filesystems and wreak any and every kind of havoc –including killing the system.

That’s why the root account can sometimes be demmed too powerful/dangerous for every day use, something like driving a Mercedes to go three blocks down the street to get a can of soda. So it’s no surprise that some distros, specially those not aimed to expert users deactivate the root account by default –Ubuntu and Freespire are two such examples.

The safe thing to do in any distro is to get everyday access as a normal user and become the root only when dealing with a task that really needs administrative privileges. You don’t need to log in as root for that: as long as you have the root’s password, you can run any administrative task using the sudo command.

A simple example: creating a new user with sudo.

You need to do something that needs root privileges, say, create the new user joe and you logged in from you every day not-ultra-powerful account. What you do is to call the task through the sudo command:

sudo adduser pepito [ENTER]

then the system will ask for the root’s password, and that’s it, joe is added with the system’s default profile for new users.

Starting a new shell session as a superuser.

Sudo turns a bit irritating when you need more than a couple of lines as super user. Still, you don’t need to restart your session, you can just start a new shell session as a superuser and knock yourself up. Just type:

sudo /bin/bash

Not always optional.

Even if you are used to log in as root all the time, knowing the sudo trick is still useful because not all distros will allow you to log in as root.

Ubuntu, which has become exceedingly popular, has no root user activated by default so all the interesting stuff has to be done through the sudo command. Freespire is in a similar situation and, generally speaking, most LiveCDs put the root user in the background.


Aug 23 2007

apt-get

Tag: Distros, Essential Commands, LinuxVlogcanic @ 3:51 pm

The Advanced Packaging Tool (APT) is one of the most remarkable contributions made by the The Debian Project to the wider Linux community. It’s a package manager first introduced with Debian GNU/Linux 2.1 in 1999.

APT is frequently hailed as one of Debian’s (and derivatives)stronger features. The tool is so well respected that it’s spawned several projects aimed to port it into other operating systems such as OpenSolaris and Mac OS X not to mention other Linux flavors and packaging systems (apt-rpm, for instance, is an APT for Red Hat and systems using the rpm packagin system such as SuSE).

APT’s flagship user application is the line command apt-get which is included by default with any Debian or Debian-based distribution.

Using apt-get is simple enough. All you need is to know what package you want to install –but by name, every package has a short name, that’s the one you need to know.

Using apt-get to install or remove packages and other useful options.

For instance, let’s say you want NDISWrapper installed in your Linux (say it’s Ubuntu). The thing to know is that the package’s name in the repository is not NDISWrapper but ndiswrapper-common, so you open up a terminal and type this

sudo apt-get install ndiswrapper-common

you give the system your password and if you haven’t installed other packages needed for this one to work in advance, apt-get is going to search them up and install them for you by itself.

apt-get has plenty of other functionalities besides package installation. The most obvious one is the removal of packages. If you got fed up of NDISwrapper and want to uninstall it you simply go to the terminal and write

sudo apt-get remove ndiswrapper-common

Other very useful options are:

apt-get update to resynchronize the packages database in your system with those in the repositories.

apt-get upgrade to have all your installed packages upgraded to the newest available version (you need to run the apt-get update beforehand).

apt-get source [package-name] to download the package’s source code.

apt-get dist-upgrade will upgrade your whole distro (so if you’re running Ubuntu Feisty Fawn 7.04 you’ll go to Gutsy Gibbon 7.10).

Note: if you are going to install a big package or anything that needs a big download, make sure you do it while your resources are availalbe (your bandwith is clear, enough disk space, etc) in order to do the thing in one go. It makes life easier.

Installing multiple packages.

You don’t need to write a line for every package you want. You can instead type all the package’s names in one single command

sudo apt-get install [name1] [name2] [name3]

apt-get with a GUI

If you are less of a typer and more of a point and clicker, there are plenty of options for you to use apt-get. GNOME’s Synaptic Package Manager, for instance, is a GTK+ graphical front end for apt-get (with some extra advantages such as a searchable package index). KDE has the Adept Package Manager.


Aug 11 2007

modprobe

Tag: Essential Commands, LinuxVlogcanic @ 3:55 pm

The program modprobe is a system administration command in Linux capable of managing (viewing, injecting and unloading) kernel modules. Module is Linuxspeak to address the kind of software that does the same trick as drivers do in Windows.

A brief description.

Upon boot modprobe typically checks the contents in three locations of the Linux filesystem:

  • /lib/modules/`uname -r` which is the directory where are the loadable modules and related files are stored for the current kernel.
  • /etc/modules, a text file containing a list of optional modules to be loaded by default.
  • /etc/modprobe.d/blacklist, another text file, the black list, which contains the module names that must not be loaded into the kernel under any circumstances.

note: this may vary depending on the distribution, the conventions described here are those used by Debian and Debian-based systems

Basic use and options.

Let’s say that modulename is the module you want to inject into the running kernel. In order to inject it you type

modprobe modulename

as the root user or

sudo modprobe modulename

otherwise. Once that’s done you can check that the module is indeed loaded by asking modprobe to show you a list of all the loaded modules

modprobe -l

or

modprobe --list

which is kind of impractical as the list is usually rather long. But you can also ask for a specific module or use wildcards

modprobe -l modulename

You can also unload the module from the kernel by calling modprobe with the remove option typing

modprobe -r modulename

as the root user or

sudo modprobe –remove modulename

otherwise.

Modprobe removes modules by calling the rmmod program, which you can also use directly.

For more options, look at your system’s manual documentation:

man modprobe

Aug 10 2007

rmmod

Tag: Essential Commands, LinuxVlogcanic @ 3:28 pm

The program rmmod is an essential system administration command in Linux used to unload a loadable module from a running kernel. In order to succeed the module to be removed must meet two conditions:

  • it must not be in use by the system
  • it must no be in use by any other module.

For instance, if NDISWrapper is running as a loaded module on your kernel you can remove it by typing

rmmod ndiswrapper

as a root or

sudo rmmod ndiswrapper

as some other user.

The same thing can be done by using the modprobe command with the remove option –ultimately, modprobe calls rmmod to do the trick.

modprobe -r ndiswrapper

How to remove a module in use.

If a module is in current use it can’t be removed immediatly but rmmod can be called in waiting mode in order to block new access requests from any running process and then have it unloaded when it’s no longer in use. The waiting option can be called either by

rmmod -w modulename

or

rmmod --wait modulename

Aug 03 2007

pwd

Tag: Essential Commands, LinuxVlogcanic @ 3:26 pm

Any Linux/Unix file system is a veritable labrynth in which getting lost is both easy an undesirable, specially while being logged in as the root or superuser –messing around with the wrong file can jump back at you. Having a stroll around the fs, however, is also unavoidable whenever you need to perform any task slightly more interesting than a ping.

pwd is one of those commands so seemingly simple that its usefulness often goes under the radar. Yet it can save you a lot of time and frustration whenever the piece of information you need is to know where the hell in the filesystem you currently are.

Its invoked by typing

pwd

and that’s it. It returns your current path.

Nothing simpler, nothing more useful.