Before you begin, generate a Key file Pair using a tool like Puttygen!!
Add a User
useradd -c “<name.lastname>” -s /bin/bash -m <username>
openssl rand -base64 6 | tee -a ~<username>/.password | passwd –stdin <username>
This creates the user and saves a random Password for him
copy the public key file to the user’s home directory and and set the permissons
mkdir ~<username>/.ssh
chmod 700 ~<username>/.ssh
cp <rsa public key file> ~<username>/.ssh/authorized_keys
chmod 600 ~<username>/.ssh/authorized_keys
chown -R <username>:users ~<username>/.ssh
This should be working in most linux distros.
Make sure ssh is configured properly (/etc/ssh/sshd_config)
Also check the authorized_keys content with VI and make sure that the key itself is all on one line.
So it would look something like:
ssh-rsa <the key in one line>