Showing posts with label administration. Show all posts
Showing posts with label administration. Show all posts

Wednesday, July 15, 2009

Add Linux users with a crypted password

If you routinely setup Linux systems with the same user accounts, you might find it helpful to be able to add the users with a single command, without typing in the password and other info for each user like you have to do with adduser. A single-line, no-questions-ask command also lends itself well to batch scripting.

To do this you'll need to know the username, the system user id and group id (UID and GUID) and plain text password for the user you're about to add.

Start by making the crypted password hash. You can make the password hash with the following command (this is tested on Debian Linux):

    mkpasswd -H md5

mkpasswd will ask you for the password:

    Password:

Type in your password, hit enter and mkpasswd will show you the hash:

    $1$uv.y5wtb$remRyh2SeDD9mgZ81aYuB1

Here is the full command. Put the hash mkpasswd printed in single quotes at the end of the line like this:

    useradd -g 1003 -m -u 1003 -s /bin/bash johndoe -p '$1$uv.y5wtb$remByh2ShDD9mgZ81aYuB1'

The shell parameter "-s /bin/bash" is not strictly necessary but I've found it best to include it to avoid potential accidents.

Note that when using useradd like this, the groups must be preexisting. If the group doesn't already exist, add it with:

    groupadd groupname

It's a good idea to clear your shell history after adding all your users this way. An easy way to clear the history is by running the following commands, one at a time:

    HISTFILESIZE=1
    ls
    ^d

(^d means Ctrl-d: hold down the control key, tap the d key, then let go of the controll key)

Wednesday, October 15, 2008

Emacs Example Tutorial: insert a block of text

As I explained in my previous Emacs tutorial on killing a block of text, it is sometimes hard to find easy to understand documentation on how to use emacs.
One of the first things I wanted to learn how to do in Emacs was block editing. By "block editing" I mean select a vertical area of text (one or more columns across multiple rows making a square or rectangle - you might call it zero or more since you don't actually have to select any characters, only the spaces between them) and do things to it - you might call it column editing or column mode or "Block Mode Editing" like in Kate, or UltraEdit.

Inserting a column of characters in emacs (without using a mouse) is really easy: you start by highlighting or selecting an area - when you do this you are said to "mark" the region.

You mark a region by positioning your cursor in one corner of the area you want to mark and hitting Control-Spacebar. You will see Emacs respond with the message "Mark set". Then navigate your cursor (I always use the arrow keys, but there is probably other ways to do it) to the opposite corner of the region you want to mark. The "region" is now marked as a rectangle between wherever you started (when you hit Ctrl-Space) and wherever your cursor is now sitting. Note that you don't do anything special to mark the end of the region -- the end is where ever your cursor is positioned.

Emacs calls the space you've now selected the "region-rectangle". Once it's highlighted, you can insert characters into the region by typing:

C-x r t

(That means press x while holding down the control key, release both keys, press and release the r key, press and release the t key). Emacs will respond with the message "String rectangle": it is asking you what text you wish to insert. Type what ever characters (letters) you want to "paste" into the region, and hit enter. It will automatically fill in that same text on every line that you've selected in your region.

I find this to be a great way to comment out areas of code with # characters. Emacs also has a "comment region" command which sometimes works, but occasionally emacs is too smart for it's own good and doesn't know what comment character to use (in which case it will usually ask you which to use with the question "No comment syntax is defined. Use:"), or worse it will use the wrong one.

You can use the comment region function by selecting a region in the same manner descried above, then type:

M-x comment-region

(That means press x while holing down the ALT key, release both keys, type "comment-region" - without the quotes of course - and hit enter).

I find C-x r t easier and faster to use than "M-x comment-region" in most cases anyway. It's fewer letters to type, even when you consider tab completion.

Tuesday, March 6, 2007

An Easy Linux-VServer Tutorial

At work we are always needing "one more computer . . ." for endless tasks, tests, development environments, secure areas, workspace for "untrusted" personnel that does not give them access to the rest of our project areas - the list is endless.

We've tried quite a lot of things over the years, including attempting to roll my own secure "jailed" system using SELinux on SuSE combined mini Debian install in a chrootjail (it didn't work :-) ).

Other projects that deserve honorable mention include bochs, xen, various jails and restricted shell, VMWare, VirtualBox.

Recently I've come across "Linux-VServer", which gave me a refreshing surprise: it is easy to install and use, resonably secure, and certainly self-contained.

I found a pretty good, brief article describing how to setup Linux_VServer under Debian Etch, but it left out a few important details (like how to get ssh access to your new install!), so I wrote a "helper" article describing in more detail the steps for a quick, easy install.

If you are interested you can read my article here:

http://www.cedarcreeksoftware.com/articles/general/an-even-easier-linux-vserver-tutorial.html