Archive

Archive for the ‘ssh’ Category

How to automatically start Apache on Solaris 9 reboot/boot

July 6th, 2009

Here’s how you can have Apache automatically start on system reboot/boot on Solaris 9.

  1. become root user
  2. cd /etc/init.d
  3. ls -al to see if there is a file named “apache.”
  4. If not, create a file named “apache” with the following:
  5. #!/sbin/sh
    #
    # Copyright 2004 Sun Microsystems, Inc. All rights reserved.
    # Use subject to license terms.
    #
    #ident “@(#)apache.sh 1.3 04/07/18 SMI”

    APACHE_HOME=/usr/local/apache2
    CONF_FILE=/usr/local/apache2/conf/httpd.conf
    PIDFILE=/var/run/httpd.pid
    TOMCAT_CF=/var/apache/tomcat/conf/server.xml

    if [ ! -f ${CONF_FILE} ]; then
    exit 0
    fi

    # see if we need to start/stop tomcat also

    CF=`egrep ‘^[ \t]*include[ \t]*/etc/apache/tomcat.conf’ $CONF_FILE`
    if [ -n "$CF" -a -f $TOMCAT_CF ]; then
    TOMCAT=yes
    TC_USER=`egrep ‘^[ \t]*User[ \t]‘ $CONF_FILE | nawk ‘{print $2}’`
    else
    TOMCAT=no
    fi

    case “$1″ in
    start)
    /bin/rm -f ${PIDFILE}
    cmdtext=”starting”
    if [ "x$TOMCAT" != xno ]; then
    (CATALINA_HOME=${APACHE_HOME}/tomcat; export CATALINA_HOME; \
    CATALINA_BASE=/var/apache/tomcat; export CATALINA_BASE; \
    JAVA_HOME=/usr/java; export JAVA_HOME; \
    /bin/su $TC_USER -c \
    “$CATALINA_HOME/bin/startup.sh”) \
    >/dev/null 2>&1
    fi
    ;;
    restart)
    cmdtext=”restarting”
    ;;
    stop)
    cmdtext=”stopping”
    if [ "x$TOMCAT" != xno ]; then
    (CATALINA_HOME=${APACHE_HOME}/tomcat; export CATALINA_HOME; \
    CATALINA_BASE=/var/apache/tomcat; export CATALINA_BASE; \
    JAVA_HOME=/usr/java; export JAVA_HOME; \
    /bin/su $TC_USER -c \
    “$CATALINA_HOME/bin/shutdown.sh”) \
    >/dev/null 2>&1
    fi
    ;;
    *)
    echo “Usage: $0 {start|stop|restart}”
    exit 1
    ;;
    esac

    echo “httpd $cmdtext.”

    /bin/sh -c “${APACHE_HOME}/bin/apachectl $1″ >/dev/null 2>&1
    status=$?

    if [ $status != 0 ]; then
    echo “exit status $status”
    exit 1
    fi
    exit 0

  6. Make sure the APACHE_HOME and CONF_FILE have the correct paths.
  7. chmod 744 /etc/init.d/apache
  8. Test your script to make sure it works:
    ./apache start
  9. cd /etc/rc3.d
  10. See if the “S50apache” symbolic link exists in that directory. If not then create the symbolic link (make sure you are not going to overwrite anything)
    ln -s /etc/init.d/apache S50apache
  11. Reboot the system by typing:
    /usr/sbin/reboot

apache, linux/unix, migration, php, ssh, web server

SSH Authorized Keys setup – login with no password

March 6th, 2009

SSH Authorized keys allow you to login to a Linux server with no password. This is particularly helpful if you are running an automated script, like a cron job.

For this example, let’s say you want to login in to server B from server A with no password.

a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory ‘/home/a/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A

Now use ssh to create a directory ~/.ssh as user a on B. (The directory may already exist, which is fine):

a@A:~> ssh a@B mkdir -p .ssh
a@B’s password:

Finally append a’s new public key to a@B:.ssh/authorized_keys and enter a’s password one last time:

a@A:~> cat .ssh/id_rsa.pub | ssh a@B ‘cat >> .ssh/authorized_keys’
a@B’s password:

From now on you can log into B as a from A as a without password:

a@A:~> ssh a@B

If you would like to login to other remote server C, do not generate a new id_rsa.pub file. Just do the following:

a@A:~> cat .ssh/id_rsa.pub | ssh a@C ‘cat >> .ssh/authorized_keys’
a@C’s password:

linux/unix, ssh