I want to add a user to Red Hat Linux that will not use a password for logging in, but instead use a public key for ssh. This would be on the command line.
Start with creating a user:
useradd -m -d /home/username -s /bin/bash username
Create a key pair from the client which you will use to
ssh-keygen -t dsa
Copy the public key
/home/username/.ssh/id_dsa.pub onto the RedHat host into
Set correct permissions on the files on the RedHat host:
chown -R username:username /home/username/.ssh chmod 700 /home/username/.ssh chmod 600 /home/username/.ssh/authorized_keys
Ensure that Public Key authentication is enabled on the RedHat host:
grep PubkeyAuthentication /etc/ssh/sshd_config #should output: PubkeyAuthentication yes
If not, change that directive to yes and restart the
sshd service on the RedHat host.
From the client start an
It should automatically look for the key
~/.ssh/. You can also specify an identity file using:
ssh -i ~/.ssh/id_dsa username@redhathost
On Ubuntu you can add the user with:
adduser --disabled-password <username>
.ssh/authorized_keys file in their home directory with their public key.
You could use:
usermod --lock <username>
From the man page:
Lock a user's password. This puts a '!' in front of the encrypted password, effectively disabling the password. You can't use this option with -p or -U. Note: if you wish to lock the account (not only access with a password), you should also set the EXPIRE_DATE to 1.