SSh-passwdless login

19 views
Skip to first unread message

Mahendra gaddam

unread,
May 11, 2020, 12:45:48 AM5/11/20
to Ansible Project
Hi ,
I'm trying to setup  passwdless authentication for remote machine , when i'm doing manually it's working fine when i'm doing by shell script it's not working could you please help me out this. below is the shell script 



Thanks

filename="id_rsa"
path="$HOME/.ssh"

if [ $1 ]
then
    hostname=$1
    if [ $2 ]
    then
        username=$2
    else
        username="$USER"
    fi
else
    # Read the host and username to store public key (the host/username accepting passwordless ssh from this computer)
    #echo "What host you want to access with passwordless SSH from this computer?"
    #read hostname
    #echo "What is your username on $hostname? ($USER?)"
    #read username
    hostname=new_hostname
    username=ansible_user

    if [ ! $username ]
    then
        username="$USER"
    fi
fi


# Generate rsa files
if [ -f $path/$filename ]
then
    echo "RSA key exists on $path/$filename, using existing file"
else
    ssh-keygen -t rsa -f "$path/$filename"
    echo RSA key pair generated
fi

echo "We need to log into $hostname as $username to set up your public key (hopefully last time you'll use password from this computer)"
cat "$path/$filename.pub" | ssh "$hostname" -l "$username" '[ -d .ssh ] || mkdir .ssh; cat >> .ssh/id_rsa.pub; chmod 700 ~/.ssh; chmod 600 ~/.ssh/*'
status=$?

if [ $status -eq 0 ]
then
    echo "Set up complete, try to ssh to $host now"
    exit 0
else
    echo "an error has occured"
    exit 255
fi

Mahi 

Dick Visser

unread,
May 11, 2020, 6:35:08 AM5/11/20
to ansible...@googlegroups.com
What is the purpose of this shell script?

Please read https://docs.ansible.com/ansible/latest/user_guide/basic_concepts.html#ansible-concepts,
and then https://docs.ansible.com/ansible/latest/user_guide/connection_details.html#ssh-key-setup.
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/df7f24b9-6cb4-4cac-a6d8-5e18ed629236%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT
Reply all
Reply to author
Forward
0 new messages