Created
April 22, 2025 09:08
-
-
Save katagaki/1dc87867df9f51ac587abc26b7568986 to your computer and use it in GitHub Desktop.
Issue SSH key for a new user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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