Pages

Thursday, February 16, 2012

Changing Mac address in linux

Firstly, type

sudo ifconfig -a | grep HWaddr
 
to find the mac address of your system .ie, you will get the output as below :

eth0      Link encap:Ethernet  HWaddr b0:f3:29:68:a6:0c 

wlan0     Link encap:Ethernet  HWaddr 11:00:22:a3:g4:20 



 where the eth0 is the address for wired lan and wlan0 for wireless ie wifi.
 Now to change the mac address, type the following

ifconfig eth0 down
 
ifconfig eth0 hw ether 11:20:48:BA:d1:30 
 
you can choose the mac id you want, i.e. 11:20:48:BA:d1:30
 
ifconfig eth0 up
 
ifconfig eth0 |grep HWaddr
 
Now the mac address is changed, but it is temporary one. If u reboot, you can see ur original mac id.
The mac address is burned into your lan and it can't be changed permanently. 


Saturday, February 4, 2012

Configuring ip for lan while connecting two users using ssh.

Firstly, while connecting lan between two users using an lan cable, you have to neccessarily set the ip for two users. for this, after connecting the lan cable between two systems, now type:

              sudo ifconfig
  to check whether ur ip is set or not. If the 'inet6 addr :' is blank as shown above. Then u have to set the ip. For this type,

              sudo ifconfig eth0 192.168.1.4
 the 3rd one ie, 'eth0' may be different in different systems, suppose 'eth1' is another one. As it is shown when u type ifconfig, now regarding ip, '192.168.1.' is general used for lans based on class addresses. Now rest you can decided, i have given '4' to last one. Each system should have different ip, one system with '192.168.1.4' and another with '192.168.1.6' as you like.


ssh :secure shell 
for sharing the files through lan or wifi, you need ssh. You need to check whether the connection is established between two users, ie, type ' ping ' followed by the ip of the other computer to which u have connected. for eg:

ping 192.168.1.4

After that, type ssh in terminal to access the other systems terminal, following the ip of the other ie.


sudo ssh 192.168.1.4


Also graphical u can share a folder in you system or mount the other computer folders using the ssh, for this go to the 'connect to server' and choose the ssh and then type the ip of the other system.


if an error occurs indicating " host authentication or verification key failed" then, u have to remove the key, since changing lan connections with different system with ubuntu may arise this errors. Actually, the host key had been changed for the currently connecting system. so change the host key using the command :

ssh-keygen -f [path of hostkey filename] -R [ip of connecting system]

 sometimes, defaultly the hostkey filename would be in location '/home/[username]/.ssh/known_hosts'. Replace [username] with ur systems username.
 
you can also try the below one for the problem 
" ssh: connect to host 192.168.2.4 port 22: Connection refused "


Actually , The above error looks more like sshd is not running on host 192.168.2.4 .Try installing 'openssh-server' and if it doesnot work, then try below one:

#cd /root/.ssh

#vi known_hosts
*delete everyting on that file

#service sshd restart


Tuesday, January 31, 2012

BITBUCKET REPOSITORY CREATION

CREATING A NEW REPOSITORY

create a file named ".hgrc" and type the codes below with the username of bitbucket followed by the mail id for example

       after saving close it

1. Create a account in bitbucket
2. thus after creating the bitbucket account, click on the 'Repository' above for creating a repository , untick the private option near the name followed by clicking create repository .Afterwards copy the link given below.
3. install 'mercurial' package by typing 'sudo apt-get install mercurial'
4. now type 'hg init' in the terminal
5. again type 'hg clone ' followed by the copied link. This creates the directory of the name given.
6. Enter the directory and type 'hg add' followed by all the file names in the directory.
7. now type 'hg commit -m "any name" '
8. type 'hg push' followed by the copied link , thus after completing with asking the password of the bitbucket.


UPDATING THE EXSISTING REPOSITORY

1. copy the new files to the already created repository within the system
2. now add the new files names following the 'hg add' command within terminal
3. now follow the above step from 7
  

Wednesday, January 25, 2012

Grub Error, no such Partition found- fixing in ubuntu

Firstly, insert your current linux os bootable using either cd or usb. Now, enter into the terminal by selecting the trying option. After, taking the terminal type

sudo fdisk -l


which prints the every the partition. Select your linux partition. Mount the linux partition using mount command, ie. suppose consider /dev/sda6 is your linux partition, mount it by the following command. Before that create a directory for mounting the drive, ie,

sudo mkdir  /media/sda6

now after creating, mount the drive in the created 'sda6' directory

sudo mount   /dev/sda6  /media/sda6

after mounting, type the below command for installing grub from cd or usb

sudo grub-install --root-directory=/media/sda6 /dev/sda

thus u have installed the grub

Sunday, January 22, 2012

" No such partition, Grub Rescue error in Windows " Solution

This error occurs usually for the Laptop users, who tries to delete the Linux partition within Windows. Since, installing Linux, the Grub is installed in the Master Boot Record (MBR), which then replaces the Windows boot-loader. So, deleting the linux partition after entering windows will definitely cause the error. The Grub looks for the 'Grub file' of the linux partition, which doesn't exists and results in errors.
             For solving the it, you need Windows boot-able CD.  After inserting the CD, now select the Repair options to enter the recovery console or command prompt. Now enter
        diskpart

Select the partition, which ever is your boot-table drive. Now enter the into the boot-able drive, by type the drive letter followed by colon and press enter. For example : consider  'F' to be the bootable drive,
              C:\Users\amith> f:
              F:\>
After entering the bootable driver, enter into the 'boot' folder
             cd  boot
              
now type 
             bootsect  /nt60  SYS  /mbr
                 or
              bootrec   /nt60 SYS  /mbr 



Creating Executable files in C

Unlike any other languages C is the most efficient language which has rich set of operators and due to its non-restrictions and generality makes it convenient for programming in many areas. In this post, i would like to show, how to create your own executable commands, like general shell commands i.e,
cp - copy command for copying files,      ls - for listing all enteries within a directory,     mv - command for moving files    etc. This task is very simple.
Firstly create a C file using any editor with 'c' as extension at the end. For example, here i am using a vim editor and create a C file which prints anything you give.
vim printprogram.c



now i am going to  write the following code in the created file
// program to print input 

#include     // library file
#define FILE_END EOF     //symbolic constants

main()     // start point 
{
   char k ;    // variable declarations
   printf("Enter & press Ctrl+D when finished:");
   
   //getchar for input 
   while ( (k = getchar()) != FILE_END )  {
      putchar(k);    //output
   }
}              // end point    
after coding the file, thus proceed for its working ie, compile the file by typing the following command in the terminal
cc printprogram.c -o printpg

'cc' is the complier or you can use 'gcc' since both are same. The option '-o ' is to copy the generated machine-executable code to a file print. Now check whether it runs by again typing in the terminal, the following command
./printpg

Here the ' . ' means current directory and ' ./ ' means inside the current directory to execute the file ' printpg '. If the file is running correctly then you can proceed to next step.
change the permission of the file
chmod -c 777 printpg
Now copy the file to the bin directory, where the executable files can be run without using ' ./ ' in the terminal.
sudo cp printpg /bin/
Remove the file print in your current directory
rm printpg
now just type print in the terminal
printpg
Atlast your executable file is ready to use.

Creating Script files using Python

Open a terminal by pressing Ctrl+Alt+t or Applications->Accessories->Terminal

create a file which you want to make script. In python, create files with py as extension or just the name.
vim filename.py
now after creating the file. Code the file with program you want to use in the script. For example, i am creating an echo function which prints whatever we give.
#!/usr/bin/python
a=raw_input()
print a

save the file as usually by pressing esc and the semicolon followed by wq. After saving the file change permission of file by typing the below code
chmod -c 777 filename.py
since the executable files like cp, ls, mkdir etc are saved at /bin/ location. Thus paste the file in the bin folder as super user mode.
sudo cp filename.py  /bin/
Type your root password when asked. Now after that, the original file filename.py is still in your directory, so please remove or move it to another location. Instead of cp, you can use mv(move) in the above command, if you want to move the original file. Now just type the filename only.
filename.py
you can use just filename without any extension for creating python files, since it works. For eg:
vim filename
Thus, now you just have to enter only the filename.
Note : Keep in mind, the line in the code " #!/usr/bin/python " is important since it shows the python location in your system to the python interpreter, so that while running python files, you need not have to use python command before your file and also very important while running python scripts.
For more details on python programming, you can check python program section in the Python programming Basics post of mine. Same way, you can also create such executable files using C program, for further details on C executable files visit http://amithkp.wordpress.com/2012/01/04/executable-file-creation-in-c/ .