jueves, 19 de septiembre de 2019

Enable Root Login over SSH

1. As root, edit the sshd_config file in /etc/ssh/sshd_config:

nano /etc/ssh/sshd_config

2) Add a line in the Authentication section of the file that says PermitRootLogin yes. This line may already exist and be commented out with a "#". In this case, remove the "#".

# Authentication:
#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

3) Save the updated /etc/ssh/sshd_config file.

4) Restart the SSH server:

service sshd restart

source: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/v2v_guide/preparation_before_the_p2v_migration-enable_root_login_over_ssh

Common Issues:

If the root have locked by too many wrong authentications. Try:


usermod -U root

jueves, 12 de septiembre de 2019

How pass arguments to bash script


The getopt() function parses the command-line arguments. 
Its arguments argc and argv are the argument count and 
array as passed to the main() function on program invocation.


This is a simple example to pass 4 arguments:

#!/bin/bash

# Reading the options
TEMP=`getopt -o u:p:h:g: --long user:,password:,home:,group: -- "$@"`

eval set -- "$TEMP"

# Extractiong options and their arguments into variables

while true ; do
        case "$1" in
                -u|--user)
                        USERNAME=$2 ; shift 2 ;;
                -p|--password)
                        PASSWORD=$2 ; shift 2 ;;
                -h|--home)
                        HOMEPATH=$2 ; shift 2 ;;
                -g|--group)
                        GROUPNAMES=$2 ; shift 2 ;;
                --) shift ; break ;;
                *) echo "Internal error!" ; exit 1 ;;
        esac
done

echo "USERNAME: $USERNAME"
echo "PASSWORD: $PASSWORD"
echo "HOME: $HOMEPATH"
echo "GROUPNAMES: $GROUPNAMES"


Save the example as example_args.sh and then you can test the script:

 ./example_args.sh --user cristian --password 123456 --home /home/cristian --group mygroups

code: https://github.com/crismunoz/LinuxExamples