Archive

Archive for the ‘Unix’ Category

WinSCP

WinSCP

WinSCP is freeware SCP (Secure Copy) client using SSH (Secure Shell). Its main purpose is safe copying files between local and remote computer. Beyond this basic function, it manages some other actions with files. It can do all basic operations with files, such as copying and moving. It also allows you to rename files and folders, create new folders, change properties of files and folders. One of two selectable program interfaces allows user to manage files even on local computer. Most operations can be done recursively for files in folders. WinSCP is also available as a plugin to two file managers, FAR and Servant Salamander.

Features:

  • Integration with Windows (drag&drop, URL, shortcut icons)
  • All common operations with files
  • Support for SFTP and SCP protocols over SSH-1 and SSH-2
  • Batch file scripting and command-line interface
  • Directory synchronization in several semi or fully automatic ways
  • Integrated text editor
  • Support for SSH password, keyboard-interactive, public key and Kerberos (GSS) authentication
  • Integrates with Pageant (PuTTY authentication agent) for full support of public key authentication
  • Windows Explorer-like and Norton Commander-like interfaces.
  • Optionally stores session information.
  • Optionally supports standalone operation using a configuration file in place of registry entries, suitable for operation from removable media
  • Translated into several languages
  • Graphical user interface

OS: Windows All

Licence: Open Source GPL

Hompepage: http://winscp.net/

Download:  http://ufpr.dl.sourceforge.net/project/winscp/WinSCP/4.3.2/winscp432setup.exe

Download (Portable version): http://ufpr.dl.sourceforge.net/project/winscp/WinSCP/4.3.2/winscp432.zip

How to crypt/decrypt a file with vi?

Crypt

Open the file using vi, type “:X“, enter the key (this key will be the password to see the crypted file) and then save and exit by “:wq“.

The file will be crypted.

You can use:

vi -x yourfile

to do the same thing.

==================================================================================

Decrypt

To decrypt just the way you encrypted the file.

Open the file using vi, type “:X“, enter the key and after that the file will be visible and writable. If you close and save your file by “:wq” the file will be still crypted.

==================================================================================

To descript forever the crypted file

Open the file using vi, type “:X“, push two times the “enter” button and then save and exit by “:wq“.

The file will be decrypted

Categories: Linux, Unix

SUID [Set User ID] – SGID – [Set Group ID]

SUID – [Set User ID]

SUID bit is set for files (mainly for scripts).
The SUID permission makes a script to run as the user who is the owner of the script, rather than the user who started it.

Example:
If “xarabas” is the owner of the script and “mandrake” tries to run the same script, the script runs with the ownership of “xarabas“.
If the root user wants to give permissions for some scripts to run by different users, he can set the SUID bit for that particular script.
So if any user on the system starts that script, it will run under the root ownership.

Note:
root user much be very carefull with this.

==================================================================================

SGID – [ Set Group ID ]

If a file is SGID, it will run with the privileges of the files group owner, instead of the privileges of the person running the program.
This permission set also can make a similar impact. Here the script runs under the groups ownership.

You can also set SGID for directories.
Consider you have given 2777 permission for a directory.
Any files created by any users under this directory will come as follows.

Example:
-rw-rw-r– 1 mandrake LP1 0 Jun 11 17:30 1.txt

In the above example you can see that the owner of the file 1.txt is “mandrake” and the group owner is “LP1“.
So both “mandrake” and “LP1” will have access to the file 1.txt.

Now lets make this more intresting and complicated.
Create a directory “test“. Chmod it to 2777. Add sticky bit to it.

Example:
mkdir test
chmod 2777 test
chmod +t test

ls -al test
drwxrwsrwt 2 xarabas LP1 4096 Jun 13 2008 test

From the above permission set you can understand that SGID and sticky bit is set for the folder “test”.
Now any user can create files under the test directory.

Example:
drwxrwsrwt 2 xarabas LP1 4096 Jun 13 2008 .
-rw-rw-r– 1 mandrake LP1 0 Jun 11 17:30 1.txt
-rw-rw-r– 1 batman LP1 0 Jun 11 17:30 2.txt
-rw-rw-r– 1 joker LP1 0 Jun 11 17:30 3.txt

So all the “xarabas” user has access to all the files under the test directory.
He can edit, rename or remove the file.
mandrake” user has access to 1.txt only, “batman” has access to 2.txt only…

If sticky bit was not set for the test directory, any user can delete any files from the test directory, since the test directory has 777 permissions.
But now it not possible.

Example:
If “joker” tries to remove 1.txt
rm -f 1.txt
rm: cannot remove ‘1.txt’: Operation not permitted

Categories: Linux, Unix

Sticky bit

Sticky bit

The most common use of the sticky bit today is on directories.
When the sticky bit is set, only the item’s owner, the directory’s owner, or the superuser can rename or delete files. Without the sticky bit set, any user with write and execute permissions for the directory can rename or delete contained files, regardless of owner.
Typically this is set on the /tmp directory to prevent ordinary users from deleting or moving other users’ files

Example:
Consider you have a directory “/test“.
The chmod it to “777“, this command gives permissions for all the users to read, write and execute.
If you run chmod +t /test and now the /test directory content is the following:

Example: ls -al /test
drwxrwxrwt 2 xarabas LP1 4096 Jun 13 2008 .
-rw-rw-r– 1 xarabas LP1 0 Jun 11 17:30 1.txt
-rw-rw-r– 1 mandrake LP2 0 Jun 11 22:52 2.txt

From the above example “xarabas” is the owner of the test directory (see the first row). “xarabas” can delete or rename the files 1.txt and 2.txt. “mandrake” can delete or rename the file 2.txt only.

Concluding, if the sticky bit is set for a /test directory, only the owner of that directory or the owner of a file can delete or rename a file within that directory.

Categories: Linux, Unix

UNIX – Lesson 027 – man command and quick reference

man
With the “man” command, you can retrieve the information in the manual and display it as text output on your screen.
To use the man command, at the Unix prompt, enter:

man topic
Replace topic with the name of the manual item about which you want more information. For example, to find out more about the FTP command, at the Unix prompt, enter:

$ man ftp

==================================================================================

QUICK REFERENCE

In the first column we can see the command (obviously the command is in lower case) and in the second column a little description about the “what can do it”.

For further information you can go back in the lessons.

AT schedules a program to run at a specific time
CANCEL removes the requests from the print queue
CAT concatenates and displays the content of one or more files
CD changes working directory
CHGRP

changes the group associated with files and directories
CHMOD

changes filesystem modes of files and directories
CHOWN

changes the owner of a files and directories
COMPRESS/UNCOMPRESS

compresses/expands a file, that is replaced by new one with the extension .Z
CP

copies files or directories
CRONTAB

allows to schedule job’s execution periodically
DATE

writes the date and time
DF

reports the file system disk space
DIFF

compares the contents of file1 and file2 and writes to standard output a list of changes necessary to convert file1 into file2
DU

summarizes disk usage
ECHO

writes its arguments, separated by BLANK and terminated by a NEWLINE, to the standard output
FILE

determines the file type
FIND

descends recursively the directory hierarchy for each path seeking files that match a boolean expression
FTP

transfers file from one computer to another
GREP searches inside a text file for a pattern and prints all lines that contain the pattern
GZIP/GUNZIP

compresses/expands a file that is replaced by new one with the extension .gz
HEAD

displays the beginning of a file
HOSTNAME

sets or prints name of current host system
JOBS

displays jobs currently running (background)
KILL

sends a terminate signal to a process
LN

creates a link to a file
LP

submits print requests to a destination
LPSTAT

displays information about the current status of the LP print service
LS

lists the content of a directory
MKDIR

makes directory
MORE

displays files, one screen at a time
MV

moves or renames files or directories
PS

gets a list of process running
PWD

returns working directoryname
RLOGIN performs a remote login
RM

removes files or directories
RMDIR removes directory which must refer to an empty directory
RSH runs a command on a remote computer
SORT prints the lines of its input (or concatenation of all files listed in its argument list) in sorted order
SSH is a program for logging into a remote machine and for executing commands on a remote machine
TAIL displays the end of a file
TAR archives files
TELNET is the remote login
TOUCH creates an empty file or change modification and access time, if the file exists
UMASK sets the file mode creation mask
UNAME prints name of current system
UNIQ reports or filters out repeated lines in a file
W displays information about currently logged-in users
WC displays a count of lines, words and characters in a file
WHEREIS locates the binary, source and manual page files for a command
WHICH locates the first occurrence found in your PATH for a command
Categories: Unix

UNIX – Lesson 026 – Job and Job Scheduling – at and crontab commands

at
The “at” command is used to schedule a program to run at a specific time

Syntax :
at [-lrt]

Key argument :

  • -l   Reports all jobs scheduled
  • -r   Removes the jobs with the specified at_job_id   operands
  • -t MMddhhmm   Submits the job to be run at the time specified   by the time option-argument.

Example :
$ at -t 02261520
at> echo “Happy my dear Xarabas!“ > /tmp/Xarabas.txt
at> <EOT>
commands will be executed using /bin/csh
job 1204035720.a at Tue Feb 26 15:22:00 2008

#To exit from at command use “CONTROL+D”

$ at –l
1204035720.a    Tue Feb 26 15:22:00 2008
#To see the scheduled tasks

$ more /tmp/Xarabas.txt
Happy my dear Xarabas!

$ at -r 1204035600.a
# To cancel the scheduled task (the task number is 1204035600.a).

$ at –l

==================================================================================

crontab

The “crontab” command allows to schedule job’s execution periodically

Syntax :
crontab –l   list the content of the cronfile
crontab –e   enter in edit mode (you have to set the variable EDITOR, for example you can use “vi” editor) to change the cronfile

Cronfile consists of lines of six fields each. The first five items specify:

1. Min (0-59)
2. Hours (0-23)
3. Days of the month (1-31)
4. Months of the year (1-12)
5. Days of the week (0-6 with 0=Sunday)

An “*” indicates all legal values. Fields are separated by spaces or tabs. The last field is the program to be executed.

Example :

$ crontab –l

###########################################
#  Script to backup Databases                                           #
###########################################

#
00 01 * * 1-5  /data/s2sswd/backup/backup_GM_1_64_STCA.sh > /dev/null 2>&1
30 02 * * 1-5  /data/s2sswd/backup/backup_CM_2_64_STCA.sh > /dev/null 2>&1
#

########################################
# Script To Backup the registries on SUN_HP_01 Server  #
########################################

#
00 7 * * 1 /check/backup/backup_reg.sh  > /dev/null 2>&1
#

########################
# Script to check Samba daemon  #
########################

#
00,05,10,15,20,25,30,35,40,45,50,55 * * * * /samba_daemon/samba.awk /samba_daemon/.test > /tmp/samba_ctrl.log
#
15 18 31 12 * /samba_daemon/test.awk  /samba_daemon/.test > /tmp/samba_ctrl.log
#

The first script (backup_GM_1_64_STCA.sh) will be executed every workday (1-5) at 07:00 AM.
The second script (backup_CM_2_64_STCA.sh) will be executed every workday (1-5) at 02:30 AM.
The third script (backup_reg.sh) will be executed only the monday (1) at 07:00 AM.
The fourth script (samba.awk) will be executed every 5 minutes (every day because we have “*” in the next fields)
The fifth script (test.awk) will be executed only the 31-12 at 18:15.

Categories: Unix

UNIX – Lesson 025 – Job and Job Scheduling – Foreground, Background and jobs command

Foreground vs. Background
A foreground job can receive keyboard input and signals such as Control-C from the controlling terminal, background jobs cannot. If the login session is disconnected, foreground jobs are terminated by a hang-up signal, while backgrounds jobs are not. Both foreground and background jobs can write to the controlling terminal.

Putting a Job in the background
Jobs can be put in the background either by initiating them in the background or by stopping a foreground job and then specifying that it be continued in the background.
The way a job is initiated in the background is by putting an ampersand (&) at the end of the command line. For example, to start the excellent web browser Mozilla, if you plan on using the terminal for other activities while the web browser is running, you can type:

$ mozilla &
A second technique is to stop the foreground job with control-Z, and then to specify that the job be continued in the background with the “bg” command (The Carrot, ^, represents holding down the control key while you press the letter after it).
So, if you start Mozilla

mozilla
^Z
bg

When you run in the background a program that uses a graphical user interface for interaction, you will still be able to interact with its graphical elements in your windowing system. If you suspend it with ^Z, you will not be able to interact with it until you start it running, either in the foreground (fg) or the background (bg).

==================================================================================

jobs

The “jobs” command displays the jobs that you are running in the background and in the foreground. If the prompt is returned with no information no jobs are present.
Note: not all shells are capable of running this command.

Key argument:

-l       Reports the process group ID and working  directory of the jobs

Example :
$ xclock &
[1] 12018

$ find / -name “*.c” -print &
[2] 16619

$ jobs
[1] + Running  xclock
[2] + Running   find / -name “*.c” -print &

$ jobs -l

[1]  +  7533 Running   xclock
[2]  + 7534 Running   find / -name “*.c” -print &

$ kill %2
In order to kill the second job.

$ jobs
[1] + Running  xclock
[2] + Terminated   find / -name “*.c” -print &

Categories: Unix

UNIX – Lesson 024 – Job and Job Scheduling – ps and kill commands

In Unix, every program running on system is called process.

Each application can fork more than one process.

Each process has an identification number called :

  • PID (Process ID)

and the forking process ID is called

  • PPID (parent PID).

It is possible to run time consuming programs in background.

==================================================================================

ps

The “ps” command is used to get a list of process running

Syntax :
ps [options]

Key argument:

  • -e lists information about every process now running
  • -f generates a full listing
  • -u uidlist lists only process data whose effective user ID number or login
    name is given in “uidlist”. Normally used with “f”
    option

Example :
$ ps

PID TTY TIME COMMAND
12569 ttyp9 0:00 ps
12554 ttyp9 0:00 sh

$ ps –ef

UID PID PPID C STIME TTY TIME COMMAND
root 1 0 0 Sep 3 ? 0:54 init
root 2 0 0 Sep 3 ? 84:41 sh

$ ps –fu xarabas

UID PID PPID C STIME TTY TIME COMMAND
xarabas 1 0 0 Sep 3 ? 1:54 init
xarabas 2 0 0 Sep 3 ? 54:41 xclock

==================================================================================
kill
The “kill” command sends a terminate signal to a process

Syntax:
kill [-s signal_name [signal_number]] PID [PID …]

The kill table signal (usually used)

Signal Name Signal Number Description
HUP 1 Hang up signal
KILL 9 Kill (cannot be ignored)

Use the command
kill –l
to get a complete list of all signal

Example :
$kill 995 #by default kill send TERM signal

$kill –9 995 #send –KILL signal

Categories: Unix

UNIX – Lesson 023 – Printers and printer spooler – lp, lpstat and cancel commands

Printers and printer spooler
In this lesson we will speal about the most used command to use to print/check/cancel a submitted print.

==================================================================================
lp

The “lp” (line printer spooler) command is used to submits print requests to a destination, assigning a unique ID number.
Syntax :
lp [-d printer] [-options] filename …

Key argument :

  • -d Prints file on a specific destination.
  • -n # Prints a specific number of copies of file.
  • -q # Assigns a priority in the print queue. Specify priority-level as an integer between from 0 and 39. Use 0 to indicate the highest priority.

Example :
$ lp report # print to default printer
Request id is IT-HP405-114 (1 file)

$ lp –n2 memo1 memo2 # print two copies for every files
Request id is IT-HP405-115 (2 files)

$ ls –l | lp –d IT-HP405 # print from standard input
Request id is IT-HP405-116 (std. input)

==================================================================================
lpstat
The “lpstat” command displays information about the current status of the LP print service
Syntax :
lpstat [-tosrR]

Key argument :

  • -a lists all available printers
  • -t prints all information about the status of all printers
  • -o [printer] print the status of output requests
  • -s print a status summary, (status of the LP scheduler, default destination, list of printers etc.)
  • -r print the status of the LP request scheduler.
  • -R print a number showing the position of each request in the print queue.

Example :
$ lpstat –o
IT-HP5100-4 xarabas@itctnss0111 31781 Mar 10 18:10
IT-HP5100-5 root@itctnss0161 31823 Mar 10 18:10
IT-HP5101-856 ernescpp@itctnss0145 249752 Mar 10 18:10

$ lpstat –t
scheduler is running
no system default destination
system for IT-HP5101-l7: itctnss0145  (as printer raptor)
IT-HP5101-l7 accepting requests since Mar 10 18:17 2005
printer IT-HP5101-l7 is idle. enabled since Mar 10 18:18 2005.

$ lpstat –s
scheduler is running
system default destination: itctnss0145
system for IT-HP5101: itctnss0145 (as printer raptor)
system for IT-HP5102: itctnss0145 (as printer vtcds)

==================================================================================
cancel
The “cancel” command is used to remove the requests from the print queue

Syntax :
cancel id [id …]

Key argument :

  • -u username   Cancels jobs owned by username.

Example :
$ cancel IT-HP5100-128
Remove jobID 128 from printer IT-HP5100

$ cancel IT-HP5100
Remove current job on IT-HP5100

$ cancel -u xarabas
Remove all jobs owned by xarabas

N.B.:
The user can remove only his own request, only “root” can remove the request of other users.

Categories: Unix

UNIX – Lesson 022 – .rhost file

.rhost

.rhosts” file  is used to control which machines trust other machines for access to your account. If a machine trusts another machines then it will allow a specified user (usually yourself) to access your account without having to enter a password.
If the system administrator has configured the system to use remsh, you can use rcp/rlogin without any additional configuration.
To use rcp, require the following:
  • Read permission on the files you want to copy; read and search permission on all directories.
  • An account (login) on the remote system.
  • A “.rhosts” file in the home directory of the remote system containing the names of the local system and loginame.
Example :
hpabc leslie
Where hpabc is the name of workstation and leaslie is the local loginame.
This setting allows leslie on hpabc to copy files on the remote system containing the ”.rhosts” file.
Categories: Unix