Managing Users in uBuntu

This post is a brief description of the very basic tools used to manage users and groups in uBuntu.

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 superuberusers

Assign a user to groups

See what groups the user is in:

id tj

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_files_or_folders

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

Commonly Used File Permissions

We need to use file permissions on servers, see? it’s good, hmmkay?

This page on wikipedia treats the subject in marvelous detail, but here’s a quick reference to the levels of permissions:

Quick Reference

Octal Symbolic English
0 no permission
1 –x execute
2 -w- write
3 -wx write and execute
4 r– read
5 r-x read and execute
6 rw- read and write
7 rwx read write and execute

Commands

To query file permissions, ls -l gives you the symbolic notation.

To set file permissions, use the chmod command. ” chmod -R 755 * ” for example, sets all children of the current location to world readable and executable.

Commonly Used Permissions

OK, now, the main point of this post is to document some of the commonly used combinations. Note that in all examples below, we’re setting the last two digits the same. This is because we’re only really designing for two users: us and them. We want us to have high permissions, and only give the minimum of permissions to them.

Octal Symbolic English
000 ———- no permissions
777 -rwxrwxrwx all permissions – careful!
755 -rwxr-xr-x read and execute – necessary for scripts on a webserver
644 -rw-r–r– read only – fine for non-executable static content – images and html files.
666 -rw-rw-rw- read and write, but no execute – good for if a web page needs to modify its own configuration files, but they don’t need to be executed

Commands

World Writable 777

chmod -R 777 *

Everyone can write. Some scripts may require these settings while installing themselves.

See Also

https://help.ubuntu.com/community/FilePermissions

Tags: , , , ,

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!

Tarzan Rubberband

Ladies and Gentlemen, my personal favourite viral video of all time, Tarzan Rubberband!

After googling long and hard for a better quality version of the Tarzan Rubberband video, I’m very sad to find that the website of the artists, Jew B. & Milky Whyte, is no longer. However, you can still buy the album in MP3 format from Amazon! Click here to buy it!

Rackspace Backup

I’ve recently moved this blog to a virtual server hosted on Rackspace. Many things impress me about Rackspace, but the one thing I’m really excited about right now is the backup system. On our old managed shared hosting, HostGator, the few times we messed something up and needed to restore a full backup, we had to pay US$15 for the privilege. Now on Rackspace, I can do the same thing with a just a few clicks! Now whenever I update WordPress (for example), I make a manual backup through the rackspace management panel before proceeding, just in case I break something!

It’s this easy:

3 clicks to the backup settings

3 clicks to the backup settings

Now it’s just a matter of specifying a name for the backup, and clicking Save Backup.

Make a manual Backup

Make a manual Backup

While the backup is running, you’ll see an icon of a camera with a little grey clock overlay. When the backup is complete, the clock turns green. On my 10GB VM, this took less than a minute.

Backup in Progress

Backup in Progress

Once the backup is ready, restoring it is just as easy. Just select the backup you want to restore and click Restore Selected.

Backup Ready

Restoring a Backup

Absolutely no sweat! Thankyou Rackspace! The official Rackspace Blog also discusses a WordPress plugin for backing up WordPress files and database to storage on EC2. That’s something I’ll have to try out next! After all, this is Serious Business.

Tags: ,

StreetGeek Viral 2009

The results are in for StreetGeek Viral 2009!

StreetGeek Crotch Party by M took out 3rd place

Read Between the Blocks by Snax took out 2nd place

My Definition of a Good LAN Party by DrFrag took out 1st place

Tags: , ,

Join a uBuntu client to a Windows Active Directory Domain

Why would you want to add a uBuntu client to a Windows Active Directory Domain? I got to this point because I was unable to resolve by uBuntu servers by name.

ping beans
Ping request could not find host beans. Please check the name and try again.

Well, I never completely solved this problem, but I did work around it by adding my uBuntu servers to my domain. Then, although I still cannot resolve beans, I can now ping beans.mydomain.internal. And, it was really easy to do with a neat piece of OSS called Likewise Open.

sudo apt-get update
sudo apt-get install likewise-open
sudo domainjoin-cli join mydomain.internal Administrator
sudo update-rc.d likewise-open defaults
sudo /etc/init.d/likewise-open start

Where mydomain.internal is the domain you want to add the computer too, and Administrator is the user who has the rights to add a computer to the domain.

I rebooted at this point, but I’m told it’s not necessary to do so.

H:\>ping beans.mydomain.internal

Pinging beans.mydomain.internal [192.168.0.30]
Reply from 192.168.0.30: bytes=32 time<1ms TTL=64
Reply from 192.168.0.30: bytes=32 time<1ms TTL=64
Reply from 192.168.0.30: bytes=32 time<1ms TTL=64
Reply from 192.168.0.30: bytes=32 time<1ms TTL=64

It works!

Tags: , , , ,

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