Skip to content

Instantly share code, notes, and snippets.

@shreyansb
Created December 12, 2011 16:36
Show Gist options
  • Select an option

  • Save shreyansb/1468120 to your computer and use it in GitHub Desktop.

Select an option

Save shreyansb/1468120 to your computer and use it in GitHub Desktop.
creating a user with ssh access in unix
# create a group for the new user
groupadd shreyansgroup
# create user, -d = home directory, -g = group, -s = default shell
# note, this will not create the home directory
useradd -d /home/shreyans -g shreyansgroup -s /bin/bash shreyans
# create home directory and assign it to the user
mkdir /home/shreyans
chown shreyansgroup:shreyans /home/shreyans
# switch to the user
sudo su shreyans
# set up ssh for the user
cd /home/shreyans
mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa # creates an ssh key for the user. suppose it is named id_rsa (the default)
cd ~/.ssh
touch authorized_keys
cat id_rsa.pub >> authorized_keys
# now, get the private key to another computer somehow...
# then on the other computer:
chmod 400 ~/.ssh/id_rsa
ssh-add ~/.ssh/id_rsa
# log in!
ssh shreyans@server.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment