Pageviews

Wednesday, May 21, 2014

Tech | How to Set JAVA_HOME / PATH variables Under Linux Bash Profile


It's one of those processes you read about once, and somehow you imagine you got all the steps in your head. Well, that is the case until it rears its ugly head at critical moments of some nagging implementation.

~/.bash_profile is a startup script which generally runs once. This particular file is used for commands which run when the normal user logs in. Common uses for .bash_profile are to set environment variables such as PATH, JAVA_HOME, to create aliases for shell commands, and to set the default permissions for newly created files.

Set JAVA_HOME / PATH for a single user
Login to your account and open .bash_profile file
$ vi ~/.bash_profile
Set JAVA_HOME as follows using syntax export JAVA_HOME=. If your path is set to /usr/java/jdk1.5.0_07/bin/java, set it as follows:
export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java
Set PATH as follows:
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

Feel free to replace /usr/java/jdk1.5.0_07 as per your setup. Save and close the file. Just logout and login back to see new changes. Alternatively, type the following command to activate the new path settings immediately:

$ source ~/.bash_profile
OR
$ . ~/.bash_profile
Verify new settings:
$ echo $JAVA_HOME
$ echo $PATH

Tip: Use the following command to find out exact path to which java executable under UNIX / Linux:
$ which java
Please note that the file ~/.bashrc is similar, with the exception that ~/.bash_profile runs only for Bash login shells and .bashrc runs for every new Bash shell.

Set JAVA_HOME / PATH for all users
You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users:
# vi /etc/profile
Next setup PATH / JAVA_PATH variables as follows:
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

Save and close the file. Once again you need to type the following command to activate the path settings immediately:
# source /etc/profile
OR
# . /etc/profile

Tech | How to fix "Xlib: No protocol specified"



While installing Oracle database I was getting this error. I searched various blogs and forums and found out many solutions but lastly I got one solution which worked for me.

But well I will post all the possible ways which you can try (as per my knowledge) to overcome this issue.

Error:
Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified
Specify the display protocol by logging into the user account you are getting the error

Solution 1:
$ export DISPLAY=localhost:0.0
$ xhost +
Solution 2:
Syntax:
$ export DISPLAY=(machine_name):0.0

For example:
$ export DISPLAY=10.10.20.42:0.0
$ xhost +
Solution 3 (which worked for me)

Login to the user account where you are getting the above error
$ xauth $DISPLAY
xauth: creating  new authority file /home/oracle/.Xauthority
xauth: (argv):1: unknown command ":0.0"
The best way to check whether your Xlib display protocol is working or not is by using xclock command
$ xclock
After running this command you should see a small clock on your screen.

Solution 4
In case the above solution does not work

Login as root
# xauth $DISPLAY
xauth: creating new authority file /home/root/.Xauthority
# xauth list $DISPLAY
test.example.com/unix:0 MIT-MAGIC-COOKIE-1 f601e6a29ea688786765434c5c6325071
Now copy the above output and su to the user you are facing issue
# su - oracle
$ xauth add test.example.com/unix:0 MIT-MAGIC-COOKIE-1
f601e6a29ea688786765434c5c6325071
xauth: creating new authority file /home/oracle/.Xauthority
Now test if your DISPLAY is working
$xclock
You should get a small clock output on the screen

Tech | How to solve ssh_exchange_identification: Connection closed by remote host

Many a times when accessing a server via SSH you may end up with “ssh_exchange_identification: Connection closed by remote host” error message. For example:


ssh_exchange_identification: Connection closed by remote host
OR may be more descriptive error when you use the verbose mode (-v flag)


 OpenSSH_4.0p1, OpenSSL 0.9.7a Feb 19 2003
 debug1: Reading configuration data /etc/ssh/ssh_config
 debug1: Applying options for *
 debug1: Connecting to testserver.com [1.1.1.1] port 22.
 debug1: Connection established.
 debug1: permanently_set_uid: 0/0
 debug1: identity file /root/.ssh/identity type -1
 debug1: identity file /root/.ssh/id_rsa type -1
 debug1: identity file /root/.ssh/id_dsa type 2

The ‘ssh_exchange_identification’ issue occurs for various reasons. So to fix the issue, check the following:

1) TCP wrappers i.e. whether ssh is restricted to certain IPs in /etc/hosts.allow and /etc/hosts.deny. If yes, make sure your local IP is added in the allowed list.
Edit the /etc/hosts.allow file and add the following at the top:

sshd : yourlocalip : allow

2) The /var/empty/sshd folder should be owned by user ‘root’. Sometimes if a new application is installed, it somehow changes the ownership of the /var/empty/sshd directory resulting in ‘ssh_exchange_identification’ error message.

# chown root.root /var/empty/sshd –R

3) If the permission of the private key files are incorrect i.e. if private key files are readable by all, it also results in “ssh_exchange_identification: Connection closed by remote host” error.

For example, if any of the private key file “ssh_host_key, ssh_host_rsa_key or ssh_host_dsa_key” in /etc/ssh directory have 644 permissions, they should be set to 600.

# cd /etc/ssh
# chmod 600 ssh_host_key ssh_host_rsa_key ssh_host_dsa_key