Skip to content

Instantly share code, notes, and snippets.

@githubutilities
Last active August 10, 2023 22:14
Show Gist options
  • Select an option

  • Save githubutilities/9ee099861ff23ea9d10b to your computer and use it in GitHub Desktop.

Select an option

Save githubutilities/9ee099861ff23ea9d10b to your computer and use it in GitHub Desktop.
Linux user-group management

Linux permission management

  • chown
  • chgrp
  • chmod

User and group management

User

  • add user
# add user with prompt hints for setting up
adduser git

# add user silently without creating home directory
useradd git
# or specify a default login home directory
useradd git -d /home/git
# then change the password
passwd git
  • list all user -- cut -d: -f1 /etc/passwd
  • delete user -- userdel git or use userdel -r git to remove home directory
  • checkout user infomation -- id git

Reference

Group

  • addgroup
  • list all groups -- cut -d: -f1 /etc/group
  • checkout group infomation -- groups github
  • /etc/passwd -- users info file

git:x:1000:1000::/home/git:/bin/bash config git user to use /bin/bash

  • /etc/group -- groups info file
  • use who to see who is online
  • add User to Group -- usermod -g github git

Sudoers -- vim /etc/sudoers

ssh into servers

  • change config - vim /etc/ssh/sshd_config
  • restart sshd - service sshd restart
  • generate public key and private key
# swith to the target user
su - git

# generate rsa key
ssh-keygen -t rsa

# `authorized_keys` is the public key
# this command adds the generated public key to `sshd`'s default public key file  `authorized_keys`
mv ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 400 ~/.ssh/authorized_keys

# take the private key out and remove the private key on the server
rm –rf ~/.ssh/id_rsa

# login using private key
ssh git@<your-host> -i <path-to-your-private-key>

ssh alias

  • visit man ssh_config for more info about ssh_config
  • edit ~/.ssh/config
Host git-alias
HostName git.com
User git

Host git-server
HostName git.com
  • you can use ssh git-alias or ssh git@git-server to login which is a great life saver! visit here for more.

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment