chandrasekhar.co.uk
Independant Software Consultant & Business Owner
  HOME
  EXPERIENCE SUMMARY
King's College, London
Framestore CFC
Alt N Solutions
Bits Infotech
B2B Software
Singapore Computers
  EXPERTISE SUMMARY
  EDUCATION SUMMARY
  CODE BASE
PHP Code Base
Java Code Base
.NET code Base
Database Code Base
Linux/Windows Code Base
  CONTACT DETAILS
 

Valid HTML 4.01 Transitional

Valid CSS!

View Chandrasekhar Yeddanapudi's profile on LinkedIn

Linux/Windows Code Base
Some cool stuff which I find useful
Command Reference - Linux
Ctrl+R - To search your bash history
Kill -9 processno - To force kill the process who own
/etc/init.d/postgres/apache/mysql -restart/-stop/-start - To restart the services. you should be logged in as root to do that

Environment Control

Command                     Description

cd d                         Change to directory d
mkdir d                      Create new directory d
rmdir d                      Remove directory d
mv f1 [f2...] d              Move file f to directory d
mv d1 d2                     Rename directory d1 as d2
passwd                       Change password
alias name1 name2            Create command alias (csh/tcsh)
alias name1="name2"          Create command alias (ksh/bash)
unalias name1[na2...]        Remove command alias na
ssh nd                       Login securely to remote node
exit                         End terminal session
setenv name v               Set env var to value v (csh/tcsh)
export name="v"              set environment variable to value v (ksh/bash)

Output, Communication, & Help

Command                     Description

lpr -P printer f            
  or 
lp -d printer f              Output file f to line printer
script  [f]                  Save terminal session to f
exit                         Stop saving terminal session
mailx username               Send mail to user
man name                     Unix manual entry for name

Process Control

Command                     Description

CTRL/c *                     Interrupt processes
CTRL/s *                     Stop screen scrolling
CTRL/q *                     Resume screen output
sleep n                      Sleep for n seconds
jobs                         Print list of jobs
kill %                       Kill job n
ps                           Print process status stats        
kill  -9 n                   Remove process n
CTRL/z *                     Suspend current process
stop  %n                     Suspend background job n
cmmd&                        Run cmmd in background
bg  [%n]                     Resume background job n
fg  [%n]                     Resume foreground job n
exit                         Exit from shell

Environment Status

Command                     Description

ls  [d]  [f...]              List files in directory
ls -1  [f...]                List files in detail
alias  [name]                Display command aliases
printenv  [name]             Print environment values
quota                        Display disk quota
date                         Print date & time
who                          List logged in users
whoami                       Display current user
finger  [username]           Output user information
chfn                         Change finger information
pwd                          Print working directory
history                      Display recent commands
! n                          Submit recent command n

File Manipulation

Command                     Description

vi  [f]                      Vi fullscreen editor
emacs  [f]                   Emacs fullscreen editor
ed  [f]                      Text editor
wc  f                        Line, word, & char count 
cat  f                       List contents of file
more  f                      List file contents by screen
cat f1 f2 >f3                Concatenates f1 & f2 into f3
chmod mode f                 Change protection mode of f
cmp f1 f2                    Compare two files
cp f1 f2                     Copy file f1 into f2
sort f                       Alphabetically sort f
split  [-n]  f               Split f into n-line pieces
mv f1  f2                    Rename file f1 as f2
rm f                         Delete (remove) file f
grep 'ptn'  f                Outputs lines that match ptn
diff f1 f2                   Lists file differences
head f                       Output beginning of f
tail f                       Output end of f

Compiler

Command                     Description

cc  [-o f1]  f2              C compiler
lint f                       Check C code for errors
f77  [-o f1] f2              Fortran77 compiler
pc  [-o f1]  f2              Pascal compiler
Comparing files and email output
sdiff/diff file1 file2 | mail emailaddress@mail.com -c ccemailaddress -s \"subject details\"";
How to log in as apache if you can't
If when you do:

su apache

you get "This account is currently not available." then it's probably because that account doesn't have a shell.

You can get around this with:

su -s /bin/bash apache

(or use the shell of your choice)
Running MS-DOS commands without displaying a window (vbscript)
This actually does work as a way of running a command (for example, as a Scheduled Task), without displaying that annoying MS-DOS command window at all (not even for a second).

Create this very short vbscript and name it something like "my_script.vbs". You can then double-click that script to run it without displaying an output window or you can add that script directly to Task Scheduler.

The script should look like this:

--- start of script ---

' Command to run:
cmd = "c:mycommand.exe arg1 arg2"

' Run the command. The "0" makes the command run in a hidden window.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run cmd, 0

--- end of script ---
Setting up per-user access on vsftpd
You need to use the user_config_dir config option in your vsftpd.conf file (which is probably in /etc/vsftpd).

1. Create a dir where you can put user config files (for example /etc/vsftpd/user_configs/).

2. Add the line "user_config_dir=/etc/vsftpd/user_conf/" somewhere in your vsftpd.conf file (I added it at the end but probably it would work anywhere).

3. For EVERY user that needs to use the ftp server, there now needs to be a file matching their username in the user config dir. So if "john" used to log in via ftp, now you need to set up the file "/etc/vsftpd/user_configs/john". It can contain one or more of the config options from your main vsftpd.conf (although not all options are supported on a per-user level - see man pages).

4. If you want users to have the "default" ftp options, make their config file a symbolic li
nk to the main vsftpd.conf. For example, if we want the user "john" to have the default actions, make a symbolic link to /etc/vsftpd/vsftpd.conf called /etc/vsftpd/user_configs/john. If there's no config file or symbolic link called "john" in the user config dir then then john will get an error when he tries to connect.

5. Restart vsftpd for the settings to take effect:
/etc/init.d/vsftpd reload
Running MS-DOS commands in the background
You can use the "start" command like this:

start /B my_command
Putty problem - Unable to use key file (SSH1 private key)
If you get this message and you have already set up the SSH keys correctly, make sure that Putty is set to use the correct SSH version (1 or 2). If it's using SSH 2 and the the keys you have set up are for SSH 1 then the automatic authentication wont work and you will get the message Unable to use key file. You can change the type of SSH Putty uses in the program options for each saved session.
starting proftp
/usr/local/sbin/proftpd start
cron field order
minute, hour, day-of-month, month, day-of-week, command

Note that day-of-week is 0 = Sunday
Getting putty working using SSH keys
1. Setting up OpenSSH:

     The server needs to be set up to accept ssh keys access. In the OpenSSH config file (/etc/ssh/sshd_config) I used the following options (note that some of these options may be the default, therefore they would not need to be explicitly specified... but these are the lines I changed):

          StrictModes no
          RSAAuthentication yes
          PubkeyAuthentication yes
          AuthorizedKeysFile .ssh/authorized_keys

     After updating the config file, restart the service:

          service sshd stop
          service sshd start

2. Setting up putty:

     2.1. Getting the public and private keys:

          Using puttygen.exe:
               
               - Select SSH1 (RSA) as the type of key.
               - Use 1024 as the number of bits generated.
               - Click 'generate' and move the mouse about to generate the key.
               - Enter a key comment, such as "rangi
.robinson_desktop" (whatever you want).
               - Enter and confirm a key phrase (should be hard to guess).
               - Save the private key as a file on your machine.

          Using pageant.exe:

               - Select 'Add key'.
               - Open the private key file you saved on your machine.
               - Enter your key phrase (you have to do this whenever pageant.exe is started).

          The program pageant.exe keeps your private key in memory until it's closed, so whenever putty tries to connect to the server, it attempts to use the private key signature for authorisation.

3. Putting your private key on the server:

     - Log into your account via putty (using a password).
     - In your home directory:

          mkdir .ssh
          chmod 700 .ssh
          cd .ssh
          touch authorized_keys
          vi authorized_keys

     - Copy and paste your entire public key from puttygen.exe to the authorized_keys file.
     - Save and close the authorized_keys file.

You should now be
able to log into the server with putty using just the ssh key, no username and password required. If it's not working, try restarting sshd, as above.

Useful links:

     http://www.openssh.com/ OpenSSH website/docs
     http://www.chiark.greenend.org.uk/~sgtatham/putty/ Putty website/docs
     http://cvs.datafox-engineering.com/#top Tutorial on this subject
Unix user/file admin:
chown - change the owner of a file/dir
          
          chown rangi myfile

     chgrp - change the group of a file/dir

          chgrp

     useradd - add a user to the system

          useradd -d /home/johnny johnny

          After adding a user, you must add a password to thier account before they can use it.

     passwd - change/set password

          passwd johnny     - change johnny's password
          passwd          - change your own password

     userdel - delete a user

          userdel johnny      - delete the 'johnny' user
          userdel -r johnny - delete the 'johnny' user and his home dir
Get a list of users on the system:
more etc/passwd
inodes
inodes are data structures that contain information about files in Unix file systems. Each file has an inode and is identified by an inode number (i-number) in the file system where it resides. inodes provide important information on files such as user and group ownership, access mode (read, write, execute permissions) and type.

inodes are created when a file system is created. There are a set number of inodes, which indicates the maximum number of files the system can hold.


A file's inode number can be found using the ls -i command, while the ls -l command will retrieve inode information.
Get disk usage numbers:
df -h

     or if that doesn't work:

     df -bk
Enable directory browsing in Apache:
Add this directive to httpd.conf

     
      Options Indexes
     

     Note that the path is the full file system path, not the path relative to
     the web root dir.

     Then restart Apache:

     /etc/rc.d/init.d/httpd restart

     This all works fine on the HC remote server.
Linux set path (append path to existing path)
PATH=$PATH:/new/path
Restart Apache (2 methods)
/etc/rc.d/init.d/httpd restart

Or

/usr/local/apache/bin/apachectl restart
Find out what symbolic links are pointing to:
ls -l
Add a watermark to image with ImageMagick
composite -compose bumpmap -gravity southeast watermark.png input.jpg output.jpg

     Also, take a look at the -watermark option (this may well do this better).
Linux user admin
Create user rangi and specify home directory:

     useradd rangi -d /usr/local/rangi

Set password for rangi

     passwd rangi

Create group called chacha

     groupadd chacha

Add users to a group

     usermod -G chacha rangi
Background commands
If you wish to run a command in the background, follow it with an ampersand, so kedit & will launch the kedit application and return you to the command prompt without waiting for the application to finish.
Create an empty test file on Linux
This creates a 3gig file called myfile.

dd if=/dev/zero of=myfile bs=1M count=3072
Using Linux TSQL (from FreeTDS) to query MS SQL Se
Using Linux TSQL (from FreeTDS) to query MS SQL Server database on Windows.

Conf file being used with this installation is /usr/local/etc/freetds.conf. The
file contains the following server entry:

     [HCSERVER]
          host = 192.168.157.1     (IP of Windows machine)
          port = 1433          (The normal port for MS SQL Server)

This allows us to connect from the command line using:

     tsql -S HCSERVER -U rangi

Where rangi is a user and login in SQL Server.

NOTES

If getting an error message like "server does not exist or is not available" when
trying to connect then do the following.

     Go into SQL Server Enterprise Manager.
     Right-click the server that we are trying to connect to, select properties.
     In the Security tab, make sure the authenticaion type is
     "SQL Server and Windows" (not "Windows only")

     Click OK to exit the dialog box.
     In the tree navigator below the server, choose security->logins.
     Make sure the user name we are connecting with is present, and they are using 'SQL Server' Authentication.
     If not create it (the user must be based on a Windows user - so you might have to create one (control panel -> users))
     If yes, re-enter the password.
     Restart SQL Server.
     You should now be able to connect.
No FTP/HTTP between Windows and Linux (ping workin
CAUSES
     Hardware - if ping is working this is not the problem
     Subnet - check that computers are on same subnet
     Firewall - check that not enabled - config and startup files, see below.
     Services running - Check running, check ports, check run levels

SOLUTIONS

     Red hat (or other dist) manual
     Search error messages online
     Compare config with working machine
     Reinstall with no firewall and gnome installed (so can use gnome-lokkit)

NOTES

     I have had a case where all of these have been checked and nothing works.           Then I come back the next day and it works... why I don't know.

     Check subnet with ipconfig (win) and ifconfig(lin).

     Red hat online manual networking section is useful for looking up programs
     to specify which services are running, starting them stopping them and
     choosing if they are
started/stopped at different run levels. On a
     graphical desktop, "serviceconf" in a console is good. The console
     alternative is "netsysv", although with that one you can only edit one
     run level. "chkconfig" can be used to start/stop individual services and
     choose what run levels they run at. The Red hat online manual has a good
     explanation of these.

     Wu-fptd runs as an xinetd service. The line "disable no"
     should be in /etc/xinetd.d/wu-ftpd (not "disable yes").
     
     xinetd is restarted with "service xinetd restart".

     ipchains and iptables can be disabled (I think) with:
          chkconfig --level 0123456 ipchains off
          chkconfig --level 0123456 iptables off
     The --level is used to specify the run levels.

     When it _does_ work, if the FTP connection is slow to start, try turning
     off 'passive mode' in the FTP client.
xinetd
Restart xinetd with:
service xinetd restart
Setting and reading bash env vars
export myvar=myvalue          (sets env var)
     echo $myvar               (echos env var)
inet/xinet services
Getting access to inet/xinet services from hosts other than localhost:

     1. Ensure there is nothing in hosts.allow/deny that would deny the user

     2. Check firewall. This can be disabled for testing by typing

          lokkit

     and choosing 'none'.

     Also, see the problem below "No FTP/HTTP between Windows and Linux".
wu-ftp
Getting wu-ftp to work:

Make sure that etc/xinetd.d/wu-ftpd doesn't have the line

     disable = yes

set. It must read:

     disable = no

After making any changes to the config files you should restart xinetd:

     /etc/init.d/xinetd restart

Try

     ftp localhost

to test.
Last Updated Jul 2010