This is a very simple solution, but most guides out there make you login twice (once to scp the key) and once to put the key in authorized_keys. There\'s no need for that.
If you don\'t already have a ~/.ssh/id_rsa.pub just type "ssh-keygen -t rsa" and keep hitting enter until it\'s done :)
key=`cat ~/.ssh/id_rsa.pub`;ssh user@192.168.5.25 "echo $key >> ~/.ssh/authorized_keys"
Copy and paste the above into your shell, just be sure to change the "user@" portion to the correct user and the 192.168.5.25 to the server that you want to login without any password authentication.
Also be very sure to keep the backticks and the double quotes ", otherwise you\'ll find it won\'t work properly and tha tthe "~" will expand to the relative path on your current host, which is not what we want. The double quotes force the shell to pass the command as it should be to the target host.
echo "Enter Target Info (eg. root@192.168.1.25";read ipaddress;key=`cat ~/.ssh/id_rsa.pub`;ssh $ipaddress "mkdir ~/.ssh;echo $key >> ~/.ssh/authorized_keys"
I just prompts for the login details eg. root@192.168.5.25 and then all you have to do is enter your password and the next time you try to login it will be automatic. Remember to run "ssh-keygen -t rsa" if you haven\'t created your public/private keys in .ssh yet.
#!/bin/bash
#(c) 2016 - realtechtalk.com
#free to distribute by keeping above credit
echo "Enter the Host: username@ipaddress"
read ipaddress
echo "Setting Up Key Exchange with: \"$ipaddress\""
key=`cat ~/.ssh/id_rsa.pub`
target=$ipaddress
ssh "$target" "mkdir -p ~/.ssh;echo $key >> ~/.ssh/authorized_keys;echo 0 > /selinux/enforce;sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config"
#(c) 2010 - realtechtalk.com
#free to distribute by keeping above credit
*Disable SELinux or you can\'t login automatically on Centos 6.x
#!/bin/bash
#disable SELinux Immediately
echo 0 > /selinux/enforce
#disable SELinux Permanently
sed -i \'s/SELINUX=enforcing/SELINUX=disabled/g\' /etc/selinux/config
ssh, passwordless, logon, encryption, commandthis, guides, login, scp, authorized_keys, id_rsa, pub, quot, keygen, rsa, enable, sshd, user, echo, shell, portion, server, password, authentication, backticks, quotes, ll, tha, tthe, expand, relative, prompts, info, edit, eg, ipaddress, mkdir, bash, keyexchange, haven, bin, realtechtalk, distribute, username, selinux, enforce, sed, enforcing, disabled, etc, config, disable, automatically, centos, permanently,