Adding a user via ssh

useradd – Adding a new user
Options:

* -d home directory
* -s starting program (shell)
* -p password
* -g (primary group assigned to the users)
* -G (Other groups the user belongs to)
* -m (Create the user’s home directory

Example: To add a new user with

* a primary group of users
* a second group mgmt
* starting shell /bin/bash
* password of xxxx
* home directory of roger
* create home directory
* a login name of roger

useradd -gusers -Gmgmt -s/bin/shell -pxxxx -d/home/roger -m roger

top of page
usermod – Modifying existing user

Options:

* -d home directory
* -s starting program (shell)
* -p password
* -g (primary group assigned to the users)
* -G (Other groups the user belongs to)

Example: To add the group ‘others’ to the user roger
usermod -Gothers roger

top of page
userdel – Deleting a user

Options:

* -r (remove home directory)

Example: To remove the user ‘roger’ and his home directory
userdel -r roger

top of page
passwd – User’s Password
Options:

* user’s name (Only required if you are root and want to change another user’s password)

Example: To change the password for the account you are currently logged in as…

passwd
Enter existing password
Enter new password
Enter new password again (to validate)

Example: To change the password for the user ‘roger’ (only you are logged in as root)…

passwd roger
Enter existing password (can be either roger’s password or root’s password)
Enter new password
Enter new password again (to validate)

top of page
Where user and group information stored

User names and primary groups are stored in /etc/passwd. This file can be directly edited using the ‘vi’ editor, although this is not recommended. Format of the file is…

* User name (normally all lower case)
* Password (encrypted – only contains the letter ‘x’)
* User ID (a unique number of each user)
* Primary Group ID
* Comment (Normally the person’s full name)
* Home directory (normally /home/
* Default shell (normally /bin/bash)

Each field is separated by a colon.

Passwords for each user are stored in /etc/shadow. This file should only be changed using the passwd command.

Group information is stored in /etc/group. This file can be directly edited using the ‘vi’ editor. Format of the file is…

* Group name
* Group password (hardly ever used)
* Group ID
* User names (separated by commas)

Each field is separated by a colon.

Default files

When a new user is created, the default files and directories that are created are stored in /etc/skel.

This directory can be modified to fit your needs. Modifications only effect new users and does not change anything for existing users.

top of page
su – Switch User

To switch to another user, use the su command. This is most commonly used to switch to the root account.

Example: To switch to root account…
su
Enter root’s passwd

Example: To switch to the user ‘roger’…
su roger
Enter roger’s or root’s passwd

To return to original user, enter exit

=-=-============

summary

check a user permissions and group

id username

add a user to a group

usermod -G group1,group2 username

useradd -G developers add new user to the group developers

# passwd username * set password for the user

http://www.computerhope.com/unix/usermod.htm

Tar/Untar file and directories

Unzipping files is an important part of downloading Linux files from the Internet. In Linux a majority of the files that are downloaded are in tgz format (a gnu zipped tar file), although there are other common extensions, as shown here:

[filename].tgz
[filename].tar
[filename].tar.gz
[filename].tar.z
[filename].z

Extraction

First you upload the .tgz, .tar .tar.gz or .tar.z file to the directory on your web server designated for public Internet use. Typically this directory is named ‘www’, ‘htdocs’ or ‘web’. The file should be uploaded in BINARY format using any FTP program.

Once the installation file has been uploaded, connect to your web server using a terminal emulation program. One of the most popular of these programs is Telnet. Enter your username and password when prompted, then change to the directory on your web server designated for Internet use. If this directory is named ‘www’, you should type the following command at the prompt:

cd /usr/dom/www or cd /home/sites/me/web

Always start from the root directory (/).

With files that have the .tgz, tar.gz, or tar.z extension use this command:

tar -zxvf [filename with all extensions]

example: tar -zxvf yourfile.tar.gz

This will extract the file for you in the directory you are currently in. Using the above command will save you from having to redirect the output for gzip or anything else (because the z option automatically decompresses the file for you), otherwise without the z argument, you would have to do a command like this:

uncompress [filename with all extensions]

tar -xvf [filename with only tar extension]

Other ways to decompress files are to use:

gunzip [filename with .gz extension] – f.e. gunzip yourfile.gz

zcat [filename with .gz extension] – f.e. zcat yourfile.gz

uncompress [filename with .z extension] – f.e. uncompress yourfile.z

Not all Unix systems extract archive files with all the necessary permissions intact, therefore you should set the proper permissions on the program as required.

Using Telnet type the following at the prompt:

chmod -R 777 “directoryname”
cd “directoryname”
chmod 755 cgi-bin
cd cgi-bin
chmod 755 *.cgi
chmod 755 *.pl

You can also use most FTP clients to change the file attributes. 777 (RWX-RWX-RWX) and 755 (RWX-RX-RX) are the most widely used attributes for files relating to running most CGI scripts on a server.

other examples:

t’s often more useful to tar a directory (which tars all files and subdirectories recursively unless you specify otherwise). The nice part about tarring a directory is that it is untarred as a directory rather than as individual files.

tar cvzf foo.tgz cps100

To extract the contents of a tar file use:

tar xvzf foo.tgz

Computer , server issues and solutions