Using SSH in Ubuntu

The idea behind using SSH (secure shell) falls when one is interested in sending files over the network in secure way. There are existing methods which will accomplish the task, but SSH is a cool one when one wants real security.
Here is the step to send files securely from your machine to the other.

1. install ssh client and ssh server using
sudo apt-get install openssh-client openssh-server

2. log into the server using the command
ssh username@server
where username is the user at the server. This can be checked on local machine as ssh user@localhost

3. Now we can share files using the tool scp
to upload file use:
scp path/to/file/to/upload user@server:/path/to/host/directory
Say, to upload the file test.txt from local machine to server named someserver.com into directory /home/remote, then
scp /home/user/test.txt user@someserver.com:/home/remote

And to download file from the same server to local machine
scp user@someserver.com:/home/remote/test.txt /home/user/downloads

This one required logging every time with subsequent request of password. To setup a secure file transfer without password the way to go would be using public private combination between server and client.
Logging to SSH Server without password
Generating and using public private key
1. Creating Public Private key can be done using:
ssh-keygen -t dsa – or if you want to make rsa: ssh-keygen -t rsa
2. it will prompt you to where to put the file and the passkey for the files. take default file path. This would allow the creation of id_dsa (private key) and id_dsa.pub (public key) into the ssh directory. -> The directory would be into /home/user/.ssh/. The private key would retain with the generating server while the public key would be uploaded to the server where you would create the connection.
3. Make sure the following are available and not commented in
/etc/ssh/ssh_config
IdentityFile ~/.ssh/identity
IdentityFile ~/.ssh/id_rsa
IdentityFile ~/.ssh/id_dsa
and from /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes

4. Make sure you have id_dsa, id_dsa.pub or rsa versions on .ssh folder
5. Copy the public key to the remote server using
scp /path/to/publickey user@server:/home/user/.ssh/ – where user is the authenticated user on the remote server
6. You will be asked for one last time your password for copying the file.
7. Log to remote server using your password
8. Navigate to /home/USER/.ssh
9. having the publicKey [it is the one you scp it, like id_rsa.pub or id_dsa.pub: cat publicKey >> authorized_keys
9. The file will now be added to the remote server’s authorized_keys. This will give you an access from your machine to the remote server without password – unless you want it to.

**
Make sure the file permission for authorized_keys is 600 and
for .ssh directory it is 700
**

reference:
http://www.techotopia.com/index.php/Configuring_Ubuntu_Linux_Remote_Access_using_SSH
http://outhereinthefield.wordpress.com/2007/10/31/passwordless-scp-authentication-for-unattendedbatch-process/
http://www.debuntu.org/ssh-key-based-authentication

403 Forbidden You don’t have permission to access .. on windows pc

You don’t have permission to access error

I was trying to access my PHP web project from my Vista on my Ubunut and end up running error 403 Forbidden You don’t have permission to access on this server …

Do you know how to find missing numbers from billing records – algorithm

Well this has a very easy remedy:

BTW – I am using Uniserver – http://www.uniformserver.com/ – [ Which is the coolest development environment on windows as you would get PHP, MySQL, and PhpMyAdmin residing all at one place.]

But it doesn’t matter if you are using other tool.

1. Go to where your www folder

2. open .htaccess file using your favorite text editor – note pad is more than enough for this.

3. Under Allow From 127.0.0.1 – or whatever it is allowed Add Allow From [your ip address of the computer from which you want to access the server]

Get started with nodejs and angularJS with this tutorial

How to configure php mysql and apache

Inserting data to table reading from another table in mysql

OK, we can use INSERT INTO statement to insert fresh data to mysql. But how about if the need lies on reading data from another table?
Here is how we do it in mysql.
Let us create the tables for illustration:
Log into your mysql and create the following queries
Creating database
CREATE database testdb;
USE testdb;

Creating tables

CREATE TABLE testtbl1 (id int(10) auto_increment, fname varchar(20), lname(20), primary key(id));
CREATE TABLE testtbl2 (id int(10) auto_increment, firstname varchar(20), lastname(20), age int, primary key(id));

Lets add some data to table 2 now
INSERT INTO testtbl2 (firstname, lastname, age)
VALUES
(‘ftest1’, ‘ftest1’, 35),
(‘ftest2, ‘ftest2’, 21),
(‘ftest3, ‘ftest3’, 25),
(‘ftest4’, ‘ftest4’, 38)

Now lets add data to the first table filtering persons with age less than 30

INSERT INTO testtbl1 (fname, lname) SELECT firstname, lastname FROM testtbl2 WHERE age <= 30;

Can’t use method return value in write context – php Error

Yup, just to share – as usual.
While working on one of my projects I run this error. Here is the snippet where the error occurs:

....
        $carPrice = $this->getCarPrice(); // this would return object of CarPrice
        if (empty($carPrice->getCarPriceId()))
        {.....

Where $carPrice is an object to be returned after passing an array of data ($new_price) to the controller.
And on the next line, I was trying to if priceId of the car is not empty.
The problem is caused on the second operand of the if statement (empty($carPrice->getCarPriceId()) –
Here is how I get fool around..

...
$car_price_id = $carPrice->getCarPriceId();
if (empty($car_price_id))
{
...

It happens that function empty() [and even isset() ] do expect a variable to be checked otherwise, parse error will happen.

Adding Java Project to new Java web application on Eclipse

I just wanted to add my existing Java project to the current java web project and here is the simple step actually [of course from Eclipse :) ]

1. Right click on the web project and select Properties
2. Select J2EE Module Dependencies
3. Here either you can select the project which resides in the eclipse workspace or you can import additional external jars.
4. Apply OK
5. Right click web project and select Build Path -> configure
6. On the projects tab, select the project tab
7. Click Add and select the project that you would like to add
8. OK.
You are done! It is advisable if you clean your project and build a new one

To to do this:

Go to project -> clean and select your project
Select start a build immediately
Select build only the selected projects

After this reboot your Application Server – and enjoy with your imported project.

Networking Vista and Ubuntu

I was having some issues with Ubuntu and I wanted to re-install it. The thing is I have a lot of files there and wanted to use networking to move the data to my Vista box.
I have gone through the following steps to do so:
Assume you have a folder named data_ubuntu where all your folders and files are residing.
** in my case the computers are using wireless network
1. Go to System->Synaptic Package Manager and select and install samba from the list if it hasn’t been done already.
2. Make sure the samba version is above 3.2 and if not upgrade it.
3. Then log out and log in
4. Go to your data_ubuntu folder right click on it
5. Select sharing option and do accordingly. In my case I have set share this folder and guest for easy access.
6. Go to terminal [Applications->Accessories->Terminal] and set access permission to the shared file for others:
sudo chmod -R 775 /path/to/file/to/share/
7. This is all regarding the ubuntu part.
8 Go to your network browser from your vista machine [ Go to start menu and select Network from the right pane] and you should be able to see the name of your ubuntu machine. It may take some minutes before loading your ubuntu machine.
All set to go!

Adding auto_increment after table creation

Say the table is created like this,

mysql> CREATE TABLE customer (id int, fname varchar(20));

The above table would be created without having an index. If there is a need to make id primary key, then

mysql> ALTER TABLE customer ADD PRIMARY KEY (id);

Then adding auto_increment would be as:

mysql> ALTER TABLE customer CHANGE id id int NOT NULL AUTO_INCREMENT;

Trying to assign auto_increment before making it a primary key – if it is not already done during creation, might produce an error. Actually trying to drop the primary key before neutralizing the auto_increment would also might create an error.
The following query would take out the auto_increment part from the table

ALTER TABLE customer CHANGE id id int not null;

And, of course, after this it is possible to drop primary key.

Renaming Tables and Columns in SQL Server

Changing table or colum in SQL Server is as follows,
To change the name of the table:
sp_RENAME ‘tbloldname’, ‘tblnewname’;
To chagne the name of the column:
sp_RENAME ‘tbl.columnoldname’,’columnnewname’,’COLUMN’;

** You might face a problem on changing names of enforced (integrity) columns.

Reading CHM files in Ubuntu

There are a bunch of tools for reading CHM (Microsoft compiled help files) on Ubuntu-Linux.
A number of them are listed on the site http://www.ubuntugeek.com/how-to-view-chm-microsoft-compiled-html-help-files-in-ubuntu.html
I have tried a number of them but I like xCHM one as it keeps the tree navigation easier.
The whole installation stuff is clearly listed on the given link.

jQuery – Simple & Powerful

jQuery seems the new player as far the client side manipulation is the issue. I had always thanked JavaScript for allowing us to do the dirty job on the client side starting from validation to amazing animations and magics – as it was seen on the Google earth, we should due credit.
Then comes Ajax, yup I have loved and played with it and it is so logical. Why do I have to submit the whole page while the intension is to submit only, say, a single value like an email for subscription. Of course it has done even more than that.
And now, jQuery which is a bundle of the two nice tools. JQuery is collection of JavaScript libraries that would make coding easy, fast navigation experience and almost a shortcut to Ajax.
The functions in the jQuery are human friendly and easy to remember.
It is possible to access an element only, or a group of elements or elements under the same class in easier way. Above all uses nicely callback functions – cooool.
All one has to do to start jQuery is to download the library from http://docs.jquery.com/Downloading_jQuery and locate it like any other JavaScript code:
Following this, be ready to plough. The main character in play would be the jquery object itself. Accessing it could be done either by directly calling it or using its alias($) – which is the custom to go. How it does is: first it would select single or group of elements and then apply tasks like editing, hide/show, replacing, assigning new style and many more. Let us use the following simpe XHTML code for illustration

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title> Sample jQuery </title>
<script src="JQuery/jquery-1.3.2.min.js" type="text/javascript" ></script>
<style type="text/css">
.highlight{
background-color: palegreen;
font-family: verdana;
color: black;
font-size: 12px;
width: 300px;
}
.emphasis{
text-weight: bold;
border: solid 1px blue;
width: 300px;
}
</style>

</head>

<body>
<p id="description" class="highlight">This is for the illustration purpose</p>
<p id="attention" class="emphasis">give attention for this</P>
<a href="http://www.devx.com/codemag/Article/40923/0/page/1">More examples</a>
<input type="button" id="toggler" value="toggle" />
</body>
</html>

Basic jQuery statement would have the following format:

<script type="text/javascript">
       $(document).ready( function(){
               logic goes here;
         });
</script>

Here the ‘$’ is an alias for the jQuery object, document is the representation of documents as in DOM. The ready method makes sure if the page is ok to proceed or not.
function() inside the ready() method is the callback function. The beauty begins here, we can define any function of our own as we like.
Lets remove the highlight style from description and assign it emphais
The first part “p#description” would select the paragraph with id description. Had it been “p”, it would select all paragraphs.
In this particular case it is also possible to say (“#description”).
removeClass and addClass are self-explanatory.
The chaining is possible as a dot operated methods because each selection would return an object.
Remember how to toggle in JavaScript? Had to use if .. how about in jQuery.
Lets make a click on the first paragraph to hide and show the second paragraph.

        $("#description").click( function(event){
              $("#attention").toggle();
        });

That is all. A single line would keep our fingers from being tired.

Here, the click method would accept the callback function. This call back function is specific to the call only. Say if I have used (“p”), then when I click on a particular <p>, the click method would be applicable only to the clicked paragraph element.

	$("p#description").click(function(event){
            $(this).hide();$("p#attention").show();
        });
	$("p#attention").click(function(event){
            $(this).hide();$("p#description").show();
        });

The above snippet shows only one paragraph at a time. But it shows them alternatively.

This is just to give a very highlight about jQuery. There are a lot of things especially on the selection area.

The following are are good sources of jQuery tutorial and references
jQuery.com
http://www.devx.com/codemag/Article/40923/0/page/1
http://roshanbh.com.np/2008/03/jquery-benefits-examples-free-ebook.html