Install puTTY and run puttygen.exe (preferably run as Administrator)
Generate a key pair. Save private key. You do NOT need to save the public key.
Login into the server and go to the home folder of the user.
(either /root or /home/USERNAME)
Here is a download/fetch SH script to do tasks: sshkey.sh
#!/bin/sh
# fetch http://wp.t66.asia/sshkey.sh
echo "run puttygen.exe and generate public/private key"
echo "COPY the public key into clipboard (the pubkey starts with 'ssh-rsa AAA...'"
read -p "for username? " user
if [ -z "$user" ]; then
return 0;
fi
if [ "$user" != "root" ] && [ -e /home/$user ]; then
echo "unknown user $user"
return 0;
fi
read -p "PASTE the public key here: " pubkey
pub=$(expr "$pubkey" : '\(.......\)')
if [ "$pub" == "ssh-rsa" ]; then
if [ "$user" == "root" ]; then
mkdir /root/.ssh
chown root:wheel /root/.ssh
chmod 700 /root/.ssh
echo $pubkey > /root/.ssh/authorized_keys
chown root:wheel /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
else
mkdir /home/$user/.ssh
chown $user:$user /home/$user/.ssh
chmod 700 /home/$user/.ssh
echo $pubkey > /home/$user/.ssh/authorized_keys
chown $user:$user /home/$user/.ssh/authorized_keys
chmod 600 /home/$user/.ssh/authorized_keys
ls -la /home/$user/.ssh/
fi
sed -i "" 's|#PubkeyAuthentication yes|PubkeyAuthentication yes|g' /etc/ssh/sshd_config
service sshd restart
fi
Assuming, we want to add the key pair to user ‘admin‘:
mkdir /home/admin/.ssh # create .ssh folder
chown admin:admin /home/admin/.ssh # set group policy
chmod 700 /home/admin/.ssh # set permissions drwx——
copy the public key from puttygen (the blue highlighted incl. the ssh-rca at the beginning !) and save it in the file /home/admin/.ssh/authorized_keys
chown admin:admin /home/admin/.ssh/authorized_keys # set group policy
chmod 600 /home/$user/.ssh/authorized_keys # set permissions -rw——-
ls -la /home/admin/.ssh/ # verify
EDIT file /etc/ssh/sshd_config and uncomment line PubkeyAuthentication yes
service sshd restart # restart SSH:
Now in puTTY, you can add the private key under connection-SSH-Auth-Credentials.
And that’s it.