Archive for category Uncategorized

Managing Users in uBuntu

This post is a brief description of the very basic tools used to manage users and groups in uBuntu. Like many of my posts, this list is a quick reference of stuff you probably already know and have used before.

Add and Remove users

Add a new user. This command also creates a home directory at /home/username

adduser username

Delete a user. This command also removes the user’s home directory.

sudo deluser --remove-home username

Add and Remove Groups

Before creating a group, check if it exits

grep developers /etc/group

Then to create the group:

sudo addgroup superuberusergroup

Assign a user to groups

See what groups the user is in:

id username

Set a user’s primary group:

usermod -g primarygroup username

Add a user to another group:

usermod -a -G anothergroup username

Set resource permissions

Change ownership of resources. This command recursively sets the group owner of a file or folder to the specified group

sudo chown -R :GROUPNAME location_of_resources

Make resources group writeable. This command sets the ‘group writeable’ flag on a resource

chmod -R g+w location_of_resources

Essential Linux Commands

A brief dump of the linux commands that I can’t live without, and sometimes need a reminder on how to use. I use ubuntu, usually the latest ’stable’ release, so the example in this post and later updates will reflect that. Right now (last update) I’m running uBuntu 10.04

cat

Short for Concatenate. It’s designed for concatenating files. Use it like ‘type’ on windows for outputting file contents to the console.
Example: get the version of linux that you are running.

cat /proc/version

top

Top is the Task Manager of linux. Detailed description here. Use it to see what process is hogging your memory.

Example use:

top

wget

wget is for downloading files

Example use:

wget http://www.stuff.com/file.7z

rm

Delete stuff!

Example use: delete folder and contents

rm -f -r tempdir

find

Find stuff!

Example use: find ‘c’ files

find . -name '*.c'

Set JAVA_HOME in uBuntu

Many programs use the JAVA_HOME environment variable in Linux. Here’s how to ’set’ it permanently. Note that the paths mentioned are accurate for uBuntu 10.04, and mileage may vary with other Linux flavours.

The path to use for JAVA_HOME is ‘/usr/lib/jvm/java-6-sun‘. Check that the path exists before continuing.

Add the following line to /etc/environment. Remember to sudo to launch your text editor, as this is a privileged file.
JAVA_HOME=”/usr/lib/jvm/java-6-sun”

You’re done! If you are using a desktop environment, log out and log in again to get it to stick.

If you are connected over ssh or running on the console of the server version, run this command to get your changes to stick:
source /etc/environment

Setting up VirtualHosts in Apache2 on uBuntu (in brief)

The detailed guide on how to go this can be found here.

This post is a quick reference guide that you’ll mostly find useful if you’ve done it before.

First create the folders to put your files in:

cd /home/www
mkdir mysite.net
mkdir mysite.net/htdocs
mkdir mysite.net/cgi-bin
mkdir mysite.net/logs

Then set the appropriate permissions on the folders

chmod -R 755 mysite.net/htdocs

The apache configuration files are located in /etc/apache2/sites-available, so locate a suitable config file to start from in that folder, make a copy of it, and edit it appropriately.

Your finished config file might look something like this:


# This configuration file is for mysite.net
<VirtualHost *>
 ServerAdmin webmaster@mysite.net
 ServerNameĀ  www.mysite.net
 ServerAlias mysite.net

 # Indexes + Directory Root.
 DocumentRoot /home/www/mysite.net/htdocs/
 <Directory />
 DirectoryIndex index.php index.html
 Options FollowSymLinks
 AllowOverRide All
 </Directory>

 # CGI Directory
 ScriptAlias /cgi-bin/ /home/www/mysite.net/cgi-bin/
 <Location /cgi-bin>
 Options +ExecCGI
 </Location>

 # Logfiles
 ErrorLogĀ  /home/www/mysite.net/logs/error.log
 CustomLog /home/www/mysite.net/logs/access.log combined
</VirtualHost>

Good, now to enable your new site, execute

a2ensite mysite.net
/etc/init.d/apache2 reload

and you’re done!

Formatting Numbers in .NET

There are a few ways to convert numbers to strings.

Leading Zeroes
beans.ToString(“D4″); 0007
string.Format(“{0:00}”, beans); 07

Precision
string.Format(“{0:0.000}”, beans); 7.1234