Skip to content

Instantly share code, notes, and snippets.

@katagaki
Created April 22, 2025 09:08
Show Gist options
  • Select an option

  • Save katagaki/1dc87867df9f51ac587abc26b7568986 to your computer and use it in GitHub Desktop.

Select an option

Save katagaki/1dc87867df9f51ac587abc26b7568986 to your computer and use it in GitHub Desktop.
Issue SSH key for a new user
# This script should be run with sudo
useradd --disabled-password --create-home $1
passwd -dl $1
usermod -g sshers $1 # Use your own group if you have one, if not remove this line
mkdir -p /home/$1
chown -R $1:$1 /home/$1
sudo -u $1 ssh-keygen -f /home/$1/.ssh/rd_rsa -q -N "" # Specify a passphrase if you need one
mv /home/$1/.ssh/id_rsa.pub /home/$1/.ssh/authorized_keys
# Next few lines should ideally not be used, the private key should be transferred using another method
# rather than using the console output, which can be logged
cat /home/$1/.ssh/id_rsa
rm /home/$1/.ssh/id_rsa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment