Skip to content

Oueta

/* Nifty tech journal */

  • Home
  • MAC address lookup
  • PCI database lookup
  • Unix time converter
  • My IP Address
  • Linux Commands Cheat Sheet

Tag: Auto login

Auto login

Posted on September 26, 2017January 5, 2018 by oueta

SSH and telnet auto login on Linux and Unix with alogin.sh

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!

Posted on September 11, 2017January 6, 2018 by oueta

Telnet auto login on Linux and Unix with Expect

Telnet is obsolete because it’s insecure, an attacker that is eavesdropping your network traffic can easily steal your credentials, because telnet it’s a text-based protocol without encryption, your username and password will be sent in clear text over the network. If it’s available, always use SSH! (/linux/ssh-auto-login-on-linux-and-unix/), but if you must use telnet create and use the script from below.

Tested operating system:  Debian 9.1, CentOS 7.3, FreeBSD 11.1 and macOS 10.12


1. Check where is Expect installed, on FreeBSD 11.1  the PATH is /usr/local/bin/expect.

whereis expect

2. Create telnet.sh script and modify the username and password

#!/usr/bin/expect -f
if {[llength $argv] < 1} {
    puts "Usage: ./telnet.sh host";
    exit 1;
}
set timeout 10
set host [lindex $argv 0]
set user "my_user"
set password "my_password"
spawn telnet -l $user $host
expect {
    "?ser*" {
        send "$user\n"
        exp_continue
    }
    "?ogin*" {
        send "$user\n"
        exp_continue
    }
    "?assword*" {
        send "$password\n"
        interact
        exit 0;
    }
}
exit 1

3. Change permission and execute.

chmod 700 telnet.sh
./telnet.sh host

Warning: Keep your scripts in a safe place! Anyone who has access to your scripts can steal your credentials!

Posts navigation

Page 1 Page 2 Next page

Categories

  • Cross Platform
  • Linux
  • macOS
  • Microsoft
  • Networking
  • Unix
  • VirtualBox
  • Windows Driver
  • Windows Third Party
  • Windows Tweak
  • Wordpress

Recent Posts

  • Installing Arch Linux on a Macbook or other UEFI systems
  • Change docker0 IP Address in Linux
  • Using the ps command in Linux
  • Install vsftpd on Debian 9
  • How to change the hostname in macOS
  • Using ssh-agent for auto login with public keys in Linux
  • How to display CPU Information in Linux
  • How to connect to a Wi-Fi network via command line in Linux
  • How to generate self signed certificates for Apache2
  • How to install a LAMP server on Debian and Ubuntu
Free typing test
  • Facebook
  • Twitter
  • Google+
  • Email
Privacy Policy Proudly powered by WordPress
  • About
  • Privacy Policy
  • Terms and Conditions
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Accept