Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/Archives for ssh

October 15, 2020

SSH Script

Here’s my custom ssh script named login.sh using multiple arguments.

#!/bin/bash
if [ $# -eq 0 ]
  then
    echo 'no server supplied'
        exit 1
fi
INPUT=$2
case "$INPUT" in
  abc)
    ssh user1@$1
    ;;
  def)
    ssh user2@$1
    ;;
  *)
    ssh user3@$1
    ;;
esac

#!/bin/bash if [ $# -eq 0 ] then echo 'no server supplied' exit 1 fi INPUT=$2 case "$INPUT" in abc) ssh user1@$1 ;; def) ssh user2@$1 ;; *) ssh user3@$1 ;; esac

How to use with expected outputs.

./login.sh
no server supplied
./login.sh server3 abc
ssh user1@server3
./login.sh server2 def
ssh user2@server2
./login.sh server1
ssh user3@server1

./login.sh no server supplied ./login.sh server3 abc ssh user1@server3 ./login.sh server2 def ssh user2@server2 ./login.sh server1 ssh user3@server1

August 25, 2020

Increase SSH Timeout

Here’s how to keep your SSH timeout alive for a longer period.

Edit /etc/ssh/sshd_config. Adjust interval and count max.

ClientAliveInterval 1200
ClientAliveCountMax 3

ClientAliveInterval 1200 ClientAliveCountMax 3

ClientAliveInterval is set to 1200 and ClientAliveCountMax is set to the default which is 3. This means unresponsive SSH clients will be disconnected after approximately 3600 seconds or 1 hour.

July 27, 2020

AWS LightSail Restrict IP Address

AWS LightSail now has the ability to restrict IP addresses in their firewall rules. LightSail instances can now be secured by limiting firewall rules from an IP CIDR block or a single IP address. For example, you can restrict who can SSH into your instance by limiting it to just your IP address, so only you can SSH into your machine. Another feature AWS added in their LightSail firewall is support for ping, which could be helpful for monitoring and checks.

June 16, 2020

Copy SSH Key to Server

Here’s the command to copy a secret key to a remote server.

ssh-copy-id user@servername

ssh-copy-id user@servername

This assumes you already generated a key.

May 18, 2020

EC2 Password Authentication

When you stand up an AWS instance, it’s only accessible via SSH key using the default user, typically ec2-user.

Add password to ec2-user, then enable password authentication to ‘yes’ in SSH.

# Add password to ec2-user
sudo passwd ec2-user
# edit ssh config
vim /etc/ssh/sshd_config
# enable password authentication
PasswordAuthentication yes
# save file and exit

# Add password to ec2-user sudo passwd ec2-user # edit ssh config vim /etc/ssh/sshd_config # enable password authentication PasswordAuthentication yes # save file and exit

Restart SSH service.

systemctl restart sshd.service

systemctl restart sshd.service

  • 1
  • 2
  • 3
  • Next Page »
  • Cloud
  • Linux
  • Git

Copyright © 2012–2021