The Ulises Fasoli blog has a great password tutorial for administering Glassfish. Check the following procedure:
If I like, you don't like to enter a user / password combination every time you run the asadmin utility, you have 2 options
- Creating a password file and using the -user -passwordfile options every time you run the asadmin command (ugh ...)
- Using the asadmin login command and never think about your password, here you can implement both solutions:
1. Creating a password file
First you need to create a file that matches the directives that can be found here [ http://docs.oracle.com/cd/E19776-01/820-4495/ghytn/index.html]
AS_ADMIN_MASTERPASSWORD=mypassword AS_ADMIN_USERPASSWORD=mypassword AS_ADMIN_ALIASPASSWORD=mypassword ${glassfish_install}/glassfish/bin/asadmin --user admin --passwordfile ${glassfish_install}/glassfish-password.txt list-applications mydomain
Now, although this works fine, I find it a little tired of writing it all every time I want to execute the asadmin command, and I could write a bash script that wraps the basic asadmin tool with the -user and - parameters passwordfile pre-generated but i just don't want
2. Using the asadmin login command
The one I prefer uses the asadmin login command.
Basically what this command does, it requests your credentials in glass fish and then saves them in an encrypted file (.asadminpass) in the user's home folder
Here's how to use it:
${glassfish_install}/glassfish/bin/asadmin login Enter admin user name [default: admin]> admin Enter admin password> Login information relevant to admin user name [admin] for host [localhost] and admin port [4848] stored at [/home/user/.asadminpass] successfully. Make sure that this file remains protected.
Once this is done, you will be able to execute asadmin commands without asking for a password
${glassfish_install}/glassfish/bin/asadmin list-applications Nothing to list. Command list-applications executed successfully.
You can even store remote instances of glasses using the -host flag with the login command
[ arte@arte-epg-api2 .ssh]$ /data/glassfish/bin/asadmin login --host myremotehost.com Enter admin user name [default: admin]> admin Enter admin password> Login information relevant to admin user name [admin] for host [myremotehost.com] and admin port [4848] stored at [/home/user/.asadminpass] successfully. Make sure that this file remains protected.