With alogin.sh you can access your hosts through SSH or telnet without manually typing usernames and passwords all the time and you don’t need to hardcode the credentials into the script, you will need to define templates.
Requirements: bash and expect
Tested operating system: Debian 9.1, CentOS 7.3, FreeBSD 11.1 and macOS 10.12
In FreeBSD you may have to change the bash (env_passwd.sh) and expect (alogin.sh) path, in v11.1 they are found in /usr/local/bin/.
1. Download alogin.sh from https://github.com/oueta/alogin.sh
2. Set file permissions
chmod 600 alogin.conf env_passwd.sh README.md
chmod 700 alogin.sh
3. Edit alogin.conf and define your templates using this model: template_name:service:port:user:password.
Where service can be ssh or telnet and password can be plain text or $ for environment variable.
4. Run the script
./alogin.sh host template
Examples
alogin.conf
# template_name:service:port:user:password
# service = ssh or telnet
# password = password or $ for environment variable $TEMPLATE_NAME
mail:ssh:22:my_user:my_password
switch:telnet:23:my_user:my_password
mail.myhost.com:ssh:22:my_user:my_password
envar:ssh:22:my_user:$
We have defined four templates mail, switch, mail.myhost.com and envar, let’s use them.
The mail template will be used if the hostname contains the “mail” word.
./alogin.sh mail.example-one.com
./alogin.sh mail.example-two.com
The mail.myhost.com template will be used because it’s more specific than mail.
./alogin.sh mail.myhost.com
The mail template will be used because it’s specified in the second argument.
./alogin.sh mail.myhost.com mail
With the envar template the password will be stored in the $ENVAR environment variable.
source env_passwd.sh
env_passwd envar
./alogin.sh envar.example.com
Warning: Keep your passwords in a safe place, use the right permissions and keep in mind that root can read anything!