Skip to content

Instantly share code, notes, and snippets.

@harssh
Forked from learncodeacademy/deployUser.md
Last active September 6, 2022 13:36
Show Gist options
  • Save harssh/0dd21fccd0e369a9d6ec6f3f15949bdc to your computer and use it in GitHub Desktop.
Save harssh/0dd21fccd0e369a9d6ec6f3f15949bdc to your computer and use it in GitHub Desktop.
Adding a deploy user in Linux with some less headache goodies (not typing or using password)

(wherever it says url.com, use your server's domain or IP)

Login to new server as root, then add a deploy user

sudo useradd --create-home -s /bin/bash deploy
sudo adduser deploy sudo
sudo passwd deploy

And Update the new password

Now login as that user

Make directory .ssh on the remote server and log out

mkdir .ssh
exit

Push your ssh key to the authorized_keys file on the remote server

scp ~/.ssh/id_rsa.pub [email protected]:~/.ssh/authorized_keys

Copy SSH keys

ssh-copy-id deploy@<ubuntu-server-ip-address>

Disable password authentication

sudo vim /etc/ssh/sshd_config
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
#PermitEmptyPasswords no
PubkeyAuthentication yes

Disable password prompt for deploy user when using the sudo command

sudo visudo
# Deploy
deploy ALL=(ALL) NOPASSWD:ALL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment