You will have to enable the component called ‘universe’

Got this message while using apt-get install on ubuntu?

if so, here is how to get away with it,

go to System->administration->Software Sources
And the first tab you would see would be then check on the community maintained opensource (universe)


That would take of it.

Piping ls to cp in unix

How to copy the result of ls to directory

Actually this would be a generic implementation. But, as an illustration, if you want to pass the result of ls [list command] to copy, cp, command in unix you can do


ls /some/directory | xargs -i cp {} /new/copy/directory

Just piping the list to cp so that cp can you the listed values to copy.
As you can see this can be implemented to a lot more commands like mv, rm …

Say if you want to move the result of ls to new destination


ls /some/directory | xargs -i mv {} /new/copy/directory

How would you solve the following algorithms?

From billion numbers, find missing numbers with limited memory

Finding K complementary numbers from the given array

find specific string from files in unix and show files

This would select and print on the terminal.
Say you want to examine gullele.wordpress.com from all index.html files that are residing in some directory and sub directory
then:
find . -name ‘index.html’ -exec ‘gullele.wordpress.com’ {} ; -print
would list all index.html files with the given content inside them.

Regular expression for file and directory listing

I guess ls is a laudable command in the Linux world – the fact that everything is a file, we exploit it in a daily manner.
One usage of the a helpful command on ls is grep for listing regex’d listing.
here is the the simplest command that can list all the files/directories with that start with ‘pe’
First we would be on the directory we want the listing, then we would pipe the listing to grep!

ls | grep "^pe.*"

Even

ls | grep "^pe" 

would result the same.
One that contains pe would be

ls | grep "pe"

and the one that ends with pe would be

ls | grep "pe$"

Further reading Ubunutu help on grep

Adding PECL package in Ubuntu

I remember once enjoying PECL (PHP Extension Community Library)on my machine flourishingly. All of the sudden, I was not able find it – here is how I find out.
Trying to play with the new MongoDb, I had to install the driver from the the repository as

sudo pecl install mongo

This time I got the wrong message of not having the pecl. It was easy though – just

sudo apt-get install php5-dev

As the PECL can be found inside it.
I have read some blogs complaining this one not working and passing the problem through installing the PEAR pachage – WHICH EVER IS EASIER.
Happy PECLing..

Adding Path to Environment in Ubuntu

After adding some software or programing language or whatever to ubuntu, mostly using the non-synaptic method, our command line would crave for the new terms ;).
Here is how to add the new path to the environment
Lets use how to add the tomcat app server after we install it using the tar file.

1. Open the terminal : Application->Accessories->Terminal
2. use your favorite text editor to open /etc/environment in my case I would use view as vi /etc/environment
3. add the path on new line as CATALINA_HOME=”path/to/catalina”
4. save and exit!!
In most cases, the current shell would not see the effect and you may want to open another tab for that or you can use the export command

if we are appending to the existing path variable, we can use the export command as
export PATH = ${PATH}:/path/to/new/location – here the ${PATH} would maintain the existing path information and the colon would be the separator for the paths

Changing default Apache webroot in Ubuntu

By default the webroot for apache/php is in /var/www

To change this, say, to /home/user/workspace/public_html

1 Go to file: /etc/apache2/sites-available/default
2. Change the /var/www to /home/user/workspace/public_html – as simple as this!!

OR,

If you are changing root just to abscond some difficulty from your IDE or just for temporary purpose, you can use the symlik: just open your terminal and –
cd /home/user/workspace/public_html
ln -s /var/www/project project

by pass invalid/self signed certificate in java/glassfish – linux

The following would be handy if one wants to by pass the self signed certificate in java – for app server glassfish.
1. Go to browser and paste the url on it. Let’s assume we are using https://www.sometestcert.com/thispage.asmx
2. On the page double click the lock image [ on firefox you can get it on the right bottom corner ]. Make sure you have https not http to get that lock thing

3. Assuming you are on firefox, goto security -> view certificate -> details-> and Click Export and save it as certificate.pem – choosing x.509 certificate with chain is a good one.
4. then add the key to the glassfish’s keystore.. – say on local machine the default location for key store would be
/usr/local/glassfish/domains/domain1/config.
5. Once you go to the appropriate directory, being on terminalcd , type the following.
keytool -import -alias “sometestcert.com” -keystore cacerts.jks -file /location/to/certificate.pem
6. This time it might ask you a password, if you have specific password for the cacerts then insert it, if not the default would be changeit
7. type yes when asked if you trust the site – of course :)

enjoy certicating..

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