Pages

Monday, January 28, 2013

Apache2 in Open SUSE - Start Stop Restart


To start, stop, or manipulate Apache on a running system, use the init script /usr/sbin/rcapache2. Thercapache2 command takes the following parameters:
status
Checks if Apache is started.
start
Starts Apache if it is not already running.
startssl
Starts Apache with SSL support if it is not already running. For more information about SSL support, refer toSection 20.6, “Setting Up a Secure Web Server with SSL”.
stop
Stops Apache by terminating the parent process.
restart
Stops and then restarts Apache. Starts the Web server if it was not running before.
try-restart
Stops then restarts Apache only if it is already running.
reload or graceful
Stops the Web server by advising all forked Apache processes to first finish their requests before shutting down. As each process dies, it is replaced by a newly started one, resulting in a complete restart of Apache.





Restart Apache 2 web server, enter:

# /etc/init.d/apache2 restart

If you are using Ubuntu use sudo:

$ sudo /etc/init.d/apache2 restart

To stop Apache 2 web server, enter:

# /etc/init.d/apache2 stop
OR
$ sudo /etc/init.d/apache2 stop

To start Apache 2 web server, enter:

# /etc/init.d/apache2 start
OR
$ sudo /etc/init.d/apache2 start

Monday, January 21, 2013

Samba

A caption from http://www.samba.org/samba/docs/SambaIntro.html

What Samba Does

Samba consists of two key programs, plus a bunch of other stuff that we'll get to later. The two key programs are smbd and nmbd. Their job is to implement the four basic modern-day CIFS services, which are:
  • File & print services
  • Authentication and Authorization
  • Name resolution
  • Service announcement (browsing)
File and print services are, of course, the cornerstone of the CIFS suite. These are provided by smbd, the SMB Daemon. Smbd also handles "share mode" and "user mode" authentication and authorization. That is, you can protect shared file and print services by requiring passwords. In share mode, the simplest and least recommended scheme, a password can be assigned to a shared directory or printer (simply called a "share"). This single password is then given to everyone who is allowed to use the share. With user mode authentication, each user has their own username and password and the System Administrator can grant or deny access on an individual basis. The Windows NT Domain system provides a further level of authentication refinement for CIFS. The basic idea is that a user should only have to log in once to have access to all of the authorized services on the network. The NT Domain system handles this with an authentication server, called a Domain Controller. An NT Domain (which should not be confused with a Domain Name System (DNS) Domain) is basically a group of machines which share the same Domain Controller.
The NT Domain system deserves special mention because, until the release of Samba version 2, only Microsoft owned code to implement the NT Domain authentication protocols. With version 2, Samba introduced the first non-Microsoft-derived NT Domain authentication code. The eventual goal, of course, it to completely mimic a Windows NT Domain Controller.
The other two CIFS pieces, name resolution and browsing, are handled by nmbd. These two services basically involve the management and distribution of lists of NetBIOS names.
Name resolution takes two forms: broadcast and point-to-point. A machine may use either or both of these methods, depending upon its configuration. Broadcast resolution is the closest to the original NetBIOS mechanism. Basically, a client looking for a service named Trillian will call out "Yo! Trillian! Where are you?", and wait for the machine with that name to answer with an IP address. This can generate a bit of broadcast traffic (a lot of shouting in the streets), but it is restricted to the local LAN so it doesn't cause too much trouble.
The other type of name resolution involves the use of an NBNS (NetBIOS Name Service) server. (Microsoft called their NBNS implementation WINS, for Windows Internet Name Service, and that acronym is more commonly used today.) The NBNS works something like the wall of an old fashioned telephone booth. (Remember those?) Machines can leave their name and number (IP address) for others to see.
 Hi, I'm node Voomba.  Call me for a good time!  192.168.100.101
It works like this: The clients send their NetBIOS names & IP addresses to the NBNS server, which keeps the information in a simple database. When a client wants to talk to another client, it sends the other client's name to the NBNS server. If the name is on the list, the NBNS hands back an IP address. You've got the name, look up the number.
Clients on different subnets can all share the same NBNS server so, unlike broadcast, the point-to-point mechanism is not limited to the local LAN. In many ways the NBNS is similar to the DNS, but the NBNS name list is almost completely dynamic and there are few controls to ensure that only authorized clients can register names. Conflicts can, and do, occur fairly easily.
Finally, there's browsing. This is a whole 'nother kettle of worms, but Samba's nmbd handles it anyway. This is not the web browsing we know and love, but a browsable list of services (file and print shares) offered by the computers on a network.
On a LAN, the participating computers hold an election to decide which of them will become the Local Master Browser (LMB). The "winner" then identifies itself by claiming a special NetBIOS name (in addition to any other names it may have). The LMBs job is to keep a list of available services, and it is this list that appears when you click on the Windows "Network Neighborhood" icon.
In addition to LMBs, there are Domain Master Browsers (DMBs). DMBs coordinate browse lists across NT Domains, even on routed networks. Using the NBNS, an LMB will locate its DMB to exchange and combine browse lists. Thus, the browse list is propagated to all hosts in the NT Domain. Unfortunately, the synchronization times are spread apart a bit. It can take more than an hour for a change on a remote subnet to appear in the Network Neighborhood.

Other Stuff

Samba comes with a variety of utilities. The most commonly used are:
smbclient
A simple SMB client, with an interface similar to that of the FTP utility. It can be used from a Unix system to connect to a remote SMB share, transfer files, and send files to remote print shares (printers).
nmblookup
A NetBIOS name service client. Nmblookup can be used to find NetBIOS names on a network, lookup their IP addresses, and query a remote machine for the list of names the machine believes it ownes.
swat
The Samba Web Administration Tool. Swat allows you to configure Samba remotely, using a web browser.
There are more, of course, but describing them would require explaining even more bits and pieces of CIFS, SMB, and Samba. That's where things really get tedious, so we'll leave it alone for now.

SMB Filesystems for Linux

One of the cool things that you can do with a Windows box is use an SMB file share as if it were a hard disk on your own machine. The N: drive can look, smell, feel, and act like your own disk space, but it's really disk space on some other computer somewhere else on the network. Linux systems can do this too, using the smbfs filesystem. Built from Samba code, smbfs (which stands for SMB Filesystem) allows Linux to map a remote SMB share into its directory structure. So, for example, the /mnt/zarquon directory might actually be an SMB share, yet you can read, write, edit, delete, and copy the files in that directory just as you would local files.
The smbfs is nifty, but it only works with Linux. In fact, it's not even part of the Samba suite. It is distributed with Samba as a courtesy and convenience. A more general solution is the new smbsh (SMB shell, which is still under development at the time of this writing). This is a cool gadget. It is run like a Unix shell, but it does some funky fiddling with calls to Unix libraries. By intercepting these calls, smbsh can make it look as though SMB shares are mounted. All of the read, write, etc. operations are available to the smbsh user. Another feature of smbsh is that it works on a per-user, per shell basis, while mounting a filesystem is a system-wide operation. This allows for much finer-grained access controls.

Setup and Management

Samba is configured using the smb.conf file. This is a simple text file designed to look a lot like those *.ini files used in Windows. The goal, of course, is to give network administrators familiar with Windows something comfortable to play with. Over time, though, the number of things that can be configured in Samba has grown, and the percentage of Network Admins willing to edit a Windows *.ini file has shrunk. For some people, that makes managing the smb.conf file a bit daunting. Still, learning the ins and outs of smb.conf is a worth-while penance. Each of the smb.conf variables has a purpose, and a lot of fine tuning can be accomplished. The file structure contents are fully documented, so as to give administrators a running head start, and smb.conf can be manipulated using swat, which at least makes it nicer to look at.

List all linux groups on a box

Use any of these commands:

less /etc/group
cat /etc/group
more /etc/group
most /etc/group

or
getent group
which will show all groups: local, NIS, and LDAP (and any others available through NSS), if your box has that.

What group does a folder or file belong to?

Find out with:
for files use the command: ls -la 
for directories use the command: ls -lad

Thursday, January 3, 2013

After Changing the hosts File

I edited the hosts file at /etc/hosts , do I need to restart the service for my changes to take effect?

No, it's not necessary. You don't even need to restart the browser. The effects should take place as soon as you refresh or load a web page.

On each DNS request the hosts file is read. This means it is not saved to memory, so the changes you make are in real time.   Your machine checks the hosts file first. If a mapping is not found for a hostname, then it asks your DNS server.

Friday, December 28, 2012

man find

Man page for the find command


find

find [pathnames] [conditions]
An extremely useful command for finding particular groups of files (numerous examples follow this description). find descends the directory tree beginning at each pathname and locates files that meet the specified conditions. The default pathname is the current directory. The most useful conditions include -name and -type (for general use), -exec and -size (for advanced use), and -mtime and -user(for administrators).
Conditions may be grouped by enclosing them in \( \) (escaped parentheses), negated with !, given as alternatives by separating them with -o, or repeated (adding restrictions to the match; usually only for -name-type, or -perm). Note that "modification" refers to editing of a file's contents, whereas "change" means a modification, or permission or ownership changes. In other words, -ctime is more inclusive than -atime or -mtime.

Conditions and actions

-amin +n| -n| n
Find files last accessed more than n (+n), less than n (-n), or exactly n minutes ago.
-anewer file
Find files that were accessed after file was last modified. Affected by -follow when after -follow on the command line.
-atime +n| -n| n
Find files that were last accessed more than n (+n), less than n (-n), or exactly n days ago. Note that find changes the access time of directories supplied as pathnames.
-cmin +n| -n| n
Find files last changed more than n (+n), less than n (-n), or exactly n minutes ago.
-cnewer file
Find files that were changed after they were last modified. Affected by -follow when after -follow on the command line.
-ctime +n| -n| n
Find files that were changed more than n (+n), less than n (-n), or exactly n days ago. A change is anything that changes the directory entry for the file, such as a chmod.
-daystart
Calculate times from the start of the day today, not 24 hours ago.
-depth
Descend the directory tree, skipping directories and working on actual files first, and then the parent directories. Useful when files reside in unwritable directories (e.g., when usingfind with cpio).
-empty
Continue if file is empty. Applies to regular files and directories.
-exec command{ } \ ;
Run the Linux command, from the starting directory on each file matched by find (providedcommand executes successfully on that file—i.e., returns a 0 exit status). When commandruns, the argument { } substitutes the current file. Follow the entire sequence with an escaped semicolon (\;). In some shells, the braces may need to be escaped as well.
-false
Return false value for each file encountered.
-follow
Follow symbolic links and track the directories visited (don't use with -type l).
-fstype type
Match files only on type filesystems. Acceptable types include minixextext2xiamsdos,umsdosvfatprocnfsiso9660hpfssysvsmb, and ncpfs.
-gid num
Find files with numeric group ID of num.
-group gname
Find files belonging to group gnamegname can be a group name or a group ID number.
-ilname pattern
A case-insensitive version of -lname.
-iname pattern
A case-insensitive version of -name.
-inum n
Find files whose inode number is n.
-ipath pattern
A case-insensitive version of -path.
-iregex pattern
A case-insensitive version of -regex.
-links n
Find files having n links.
-lname pattern
Search for files that are symbolic links, pointing to files named patternpattern can include shell metacharacters and does not treat / or . specially. The match is case-insensitive.
-maxdepth num
Do not descend more than num levels of directories.
-mindepth num
Begin applying tests and actions only at levels deeper than num levels.
-mmin +n| -n| n
Find files last modified more than n (+n), less than n (-n), or exactly n minutes ago.
-mount, -xdev
Search only for files that reside on the same filesystem as pathname.
-mtime +n| -n| n
Find files that were last modified more than n (+n), less than n (-n), or exactly n days ago. A modification is a change to a file's data.
-name pattern
Find files whose names match pattern. Filename metacharacters may be used but should be escaped or quoted.
-newer file
Find files that were modified more recently than file; similar to -mtime. Affected by -followonly if it occurs after -follow on the command line.
-nogroup
The file's group ID does not correspond to any group.
-noleaf
Normally, find assumes that each directory has at least two hard links that should be ignored (a hard link for its name and one for "."--i.e., two fewer "real" directories than its hard link count indicates). -noleaf turns off this assumption, a useful practice when findruns on non-Unix-style filesystems. This forces find to examine all entries, assuming that some might prove to be directories into which it must descend (a time-waster on Unix).
-nouser
The file's user ID does not correspond to any user.
-ok command { }\;
Same as -exec, but prompts user to respond with y before command is executed.
-path pattern
Find files whose names match pattern. Expect full pathnames relative to the starting pathname (i.e., do not treat / or . specially).
-perm nnn
Find files whose permission flags (e.g., rwx) match octal number nnn exactly (e.g., 664 matches -rw-rw-r--). Use a minus sign before nnn to make a "wildcard" match of any unspecified octal digit (e.g., -perm -600 matches -rw-******, where * can be any mode).
-print
Print the matching files and directories, using their full pathnames. Return true. This is the default behavior.
-regex pattern
Like -path, but uses grep-style regular expressions instead of the shell-like globbing used in -name and -path.
-size n[c]
Find files containing n blocks, or if c is specified, n characters long.
-type c
Find files whose type is cc can be b (block special file), c (character special file), d(directory), p (fifo or named pipe), l (symbolic link), s (socket), or f (plain file).
-user user
Find files belonging to user (name or ID).

Examples

List all files (and subdirectories) in your home directory:
find $HOME -print
List all files named chapter1 in the /work directory:
find /work -name chapter1
List all files beginning with memo owned by ann:
find /work -name 'memo*' -user ann -print
Search the filesystem (begin at root) for manpage directories:
find / -type d -name 'man*' -print
Search the current directory, look for filenames that don't begin with a capital letter, and send them to the printer:
find . \! -name '[A-Z] *' -exec lpr { }\;
Find and compress files whose names don't end with .gz:
gzip `find . \! -name '*.gz' -print`
Remove all empty files on the system (prompting first):
find / -size 0 -ok rm { } \;
Search the system for files that were modified within the last two days (good candidates for backing up):
find / -mtime -2 -print
Recursively grep for a pattern down a directory tree:
find /book -print | xargs grep '[Nn] utshell'
If the files kt1 and kt2 exist in the current directory, their names can be printed with the command:
find . -name 'kt[0-9] ' ./kt1 ./kt2
Since the command prints these names with an initial ./ path, you need to specify the ./ when using the-path option:
find . -path './kt[0-9] ' ./kt1 ./kt2
The -regex option uses a complete pathname, like -path, but treats the following argument as a regular expression rather than a glob pattern (although in this case the result is the same):
find . -regex './kt[0-9] ' ./kt1 ./kt2

Source: http://www.oreillynet.com/linux/cmd/cmd.csp?path=f/find

How to Exit vi

Press escape to get into command mode if you re not already in command mode (i.e. if you are in insert/edit mode) .. Even if you are not in the edit mode press escape any way, it s OK. 

So, press esc, then

type one of these:

:q to quit and dont save
:q! to quit with out saving changes or prompts (if you have made changes)
:w to save
:wq to save and quit 


:x to save and quit 


emacs - ^X^S to save, ^X^C to quit
esc shift^ZZ to save and exit.


Notes:

Adding an exclamation mark at the end of the command means "do it!" - as in  :q!

When you will press escape the "insert" mode will be disabled, then you need to type : After that you can provide q! or w or wq and hit enter.