I'd like to setup a new user in raspbian Jessie that does not have a password and is only accessible with the correct SSH key to have a very secure of using SSH to connect to the Pi. The commands passwd and usermod won't let me unlock the user because they'll be without a password.


As root (you may need to run sudo -i or sudo su -) create a new user,

root@pi# useradd -m myuser

then su to the user

root@pi# su - myuser

and edit the file (as myuser) ~/.ssh/authorized_keys and add the public key of another computer to it,

myuser@pi$ echo "your-public-key-in-here" >> ~/.ssh/authorized_keys
# or just open in vi/nano and paste the key inside it

Also make sure that the file permissions are Read/Write only for the owner -- myuser in this case

root@pi# chmod 600 /home/myuser/.ssh/authorized_keys
root@pi# chown myuser:myuser /home/myuser/.ssh/authorized_keys
  • when trying sudo nano ~/.ssh/authorized_keys from myuser@raspberrypi system is asking me for myuser's password which doesn't exist. should i simply place the key with root user into myuser's auth_keys? – RapidFireArts Jan 3 '17 at 20:57
  • 1
    no, just edit the file as myuser you don't need sudo for that. – Rabin Jan 3 '17 at 20:59
  • i used sudo now as it didn't permit me to execute that without the correct password, but everything is working, i can ssh into myuser using the private key. is chmod 600 authorized_keys to be executed by myuser or su? it was created by su – RapidFireArts Jan 3 '17 at 21:04
  • Hi @RapidFireArts , just added some context to the commands – Rabin Jan 3 '17 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.