Friday, November 9, 2012

How to Setup SSH for Auto Login


It's common to use ssh and scp for communicating and transferring files to and from a server. If you want to auto-login without a password, here's how to setup SSH to use encryption keys to do so.

On the Server

Use ssh to login to your server under the account name you want to use.
Run ssh-keygen to create an encryption key pair, the public and private keys. You can just hit return for each question.
[backup@server ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/backup/.ssh/id_rsa):
Created directory '/home/backup/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/backup/.ssh/id_rsa.
Your public key has been saved in /home/backup/.ssh/id_rsa.pub.
CD to the .ssh dir and list the files to understand what you've got:
[backup@server ~]$ cd .ssh
[backup@server .ssh]$ ls
id_rsa  id_rsa.pub
Add the public key id_rsa.pub to the SSH authorized_keys file. Be sure to use the >> to append it to any other keys you might have:
[backup@server .ssh]$ cat id_rsa.pub >> authorized_keys
Be sure the file is hidden from other users, and you can delete the public key now.
[backup@server .ssh]$ chmod 600 authorized_keys
[backup@server .ssh]$ rm id_rsa.pub

On the Client

Log-off the server, so you're back on the client. Enter your .ssh directory and download the id_rsa file (the private key) from the server to your local machine:
$ cd .ssh
$ scp backup@server.example.com:.ssh/id_rsa .
$ chmod 600 id_rsa
Try it out:
$ ssh -l backup server.example.com
[backup@server ~]$
And you can use scp for secure file transfer:
$ scp backup.tar.gz backup@server.example.com:.

SSH Agent

You can setup an environment variable to make it possible for programs that use SSH to find your keys, avoiding the requirement than you enter your passphrase each time.
Insert some lines like this into your .bash_profile:
if [ -z "$SSH_AUTH_SOCK" ] ; then
    eval `ssh-agent -s`
    ssh-add
fi

How to setup automatic login with ssh without a password


Install a ssh client.

Download Cygwin and install the ssh package.
If you are working with us, see our recommended setup for cygwin for what else you should install.

Auto login for ssh

Excellent instructions are provided here, a summary is provided below.
  1. Login to the ssh server with your client.
  2. Generate your key pair using the following command:
    $ ssh-keygen -t rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/jurn/.ssh/id_rsa):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /home/jurn/.ssh/id_rsa
    Your public key has been saved in /home/jurn/.ssh/id_rsa.pub
    $ cd ~/.ssh
    $ cat id_rsa.pub >> authorized_keys
    $ chmod 600 authorized_keys
    Don't use any passphrase
  3. Log out of the server and go back to your local shell
    $ cd
    $ mkdir .ssh
  4. Copy the file id_rsa that was generated on the server into this directory. You can use sftp or scp for this.
  5. $ cd .ssh
    $ chmod 600 id_rsa
  6. You should now be able to login via ssh without having to prompt for a password.

Troubleshooting

In cygwin, your home is in the passwd file /etc/passwd, even if you set the $HOME environment variable
Check that the authorized_keys file on the server is not corrupted.
If you are having trouble you can use the -v option in ssh to give you some debugging info.
Lookup the man page for ssh if you are stuck.

Thursday, November 8, 2012

Install updates or packages on RHEL 5

login as root and do following ( Add repository)

cd /etc/yum.repos.d/

wget http://public-yum.oracle.com/public-yum-el5.repo

Wednesday, November 7, 2012

How to change the hostname of a Linux system


Normally we will set the hostname of a system during the installation process. Many peoples don’t care about this, and don’t change the hostname even if for example this was set to something really stupid by the datacenter that installed the system (most likely they will set this to “debian” on any debian installation, etc). For me, it is important to see on each one of the ssh screens I will have open at any time a different hostname that is relevant and will give me quickly the information on what system I am logged in.

Change the hostname on a running system

On any Linux system you can change its hostname with the command ‘hostname‘ (surprised?)… Here are some quick usages of the command line hostname:
hostname
without any parameter it will output the current hostname of the system.
hostname --fqd
it will output the fully qualified domain name (or FQDN) of the system.
hostname NEW_NAME
will set the hostname of the system to NEW_NAME. This is active right away and will remain like that until the system will be rebooted (because at system boot it will set this from some particular file configurations – see bellow how to set this permanently). You will most probably need to exit the current shell in order to see the change in your shell prompt.

Permanent hostname change on Debian based systems

Debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh
/etc/hostname
server
So on a Debian based system we can edit the file /etc/hostname and change the name of the system and then run:
/etc/init.d/hostname.sh start
to make the change active. The hostname saved in this file (/etc/hostname) will be preserved on system reboot (and will be set using the same script we used hostname.sh).

Permanent hostname change on RedHat based systems

RedHat based system use the file /etc/sysconfig/network to read the saved hostname at system boot. This is set using the init script /etc/rc.d/rc.sysinit
/etc/sysconfig/network
NETWORKING=yes
HOSTNAME="plain.domainname.com"
GATEWAY="192.168.0.1"
GATEWAYDEV="eth0"
FORWARD_IPV4="yes"
So in order to preserve your change on system reboot edit this file and enter the appropriate name using the HOSTNAME variable.

Use sysctl to change the hostname

Why would someone need a different method of doing the same thing as above? No idea, but here is anyway: use sysctl to change the variable kernel.hostname:
Use:
sysctl kernel.hostname
to read the current hostname, and
sysctl kernel.hostname=NEW_HOSTNAME
to change it.

Friday, November 2, 2012

How to do a global search/replace across files in Eclipse


The location of this command is not very intuitive. To search and replace in multiple files you need to select "Search" > "File...".


Step by step:
  1. Select the text in a file
  2. From the "Search" menu, select "File...". This will bring up the "Search" dialog box.
  3. At the bottom of the dialog, click "Replace..."
  4. This will bring up the "Replace" dialog box where you can type in your replacement text and replace individual occurrences or all occurrences.

Wednesday, October 24, 2012

type QWidget is not a direct base of MyWidget


Qt Code:

class MyWidget : public QMainWindow 
{ 
Q_OBJECT 
public: 
explicit MyWidget(QWidget *parent = 0); 

~MyWidget(); 
private: 
Ui::MyWidget *ui; 
}; 

MyWidget::MyWidget(QWidget *parent) 
: QWidget(parent)//ERROR 
{ 
QPushButton *quit = new QPushButton("Close Application", this); 

setGeometry(150,150,100,100); 
setFont(QFont("Times",12,QFont::Bold)); 

connect(quit,SIGNAL(clicked()),qApp,SLOT(quit())); 

Error: Type "QWidget" is not direct base of 'MyWidget'.
you will need to pass the parent to the QMainWindow constructor

MyWidget::MyWidget(QWidget *parent) 

: QMainWindow(parent) // no ERROR 


you will need to pass the parent to the QMainWindow constructor:

If this even does not fix the issue then you may have forgot to include the header file in .h file

# include 
 

Monday, October 22, 2012

Eclipse: convert upper case text to lower case and viceversa with a simple shortcut

This is just a quick post to share these 2 little shortcuts to convert text from lower case to uppercase and viceversa in Eclipse.

Lower case: CTRL+SHIFT+Y (CMD+SHIFT+Y on Mac OS X)

Upper case: CTRL+SHIFT+X (CMD+SHIFT+X on Mac OS X)

In both the combination you can select one or more character to convert.

you can change this setting via Eclipse > Window > Preferences > General > Keys

Friday, September 21, 2012

fixed : firmware upgrade encountered an issue on galaxy s2

The solution is pretty simple (and you don't need to buy and USB Dongle etc)

1. Connect the USB cable to the phone ( no need to connect the other end to computer etc)

2. Push Power and Volume down button. (the phone will shutdown )

3.Now once you start the phone, It will start in normal download mode.


Other option is to use only Volume down button in step 2.

- Mihir Patel

Wednesday, August 22, 2012

errno


#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Argument list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */

Thursday, August 2, 2012

Solution : Eclipse CDT to Implement Interface in C++

1. Go to the header file
2. Go to Menu item ( Source > Implement method )
3. Select the method you want to implement or select all
4. The diff will show you the difference
5. Once you accept (click finish) it will auto populate the cpp file.

- Mihir Patel