Skip to main content

Linux: Missing .SSH Folder

When creating a new linux user, the system may not create a .ssh folder in the user profile, by default.

This creates a little complexity as the permissions are a bit picky.

Here are steps to do so.

NOTE: Replace 'username' with the target user.

Create the .ssh folder in the user's profile:

sudo mkdir -p /home/username/.ssh

Set correct permissions for the .ssh folder:

sudo chmod 700 /home/username/.ssh

Create the authorized_keys file:

sudo touch /home/username/.ssh/authorized_keys

Set permissions on authorized_keys file:

sudo chmod 600 /home/username/.ssh/authorized_keys

Set ownership of the .ssh folder to the user:

sudo chown -R username:username /home/username/.ssh

Now, you can add keys to the authorized_keys file as needed, for remote SSH authentication.

Scripted Creation

The above commands can be quickly performed with this bash script:

#!/bin/bash
USERNAME="deploy"

sudo mkdir -p /home/$USERNAME/.ssh
sudo touch /home/$USERNAME/.ssh/authorized_keys
sudo chmod 700 /home/$USERNAME/.ssh
sudo chmod 600 /home/$USERNAME/.ssh/authorized_keys
sudo chown -R $USERNAME:$USERNAME /home/$USERNAME/.ssh