명령어에 대한 Syntax

  • 대부분의 명렁어는 parameter를 씀.
  • Parameter
    • argument라고도 불림
    • case-sensitive함

유저

개요

  • 리눅스 컴퓨터를 사용하는사람은 user라고 한다.

  • 시스템은 username으로 유저들을 관리함 - 유저마다 다른 권한을 부여 가능

  • 유저는 group에 속함. - 다른 요구사항을 가진 사람들의 집합으로 보안관리가 된다.

  • 커맨드

    • su : 다른 유저로 변환

      $ su - peter
      

      su vs su - su - : 로그인하고 새로운 환경변수가 적용된 새 셸을 여는것. ‘-’ -> ‘-l’ -> ‘–login’ Make the shell a login shell. This means the following. Unset all environment variables except TERM, HOME, and SHELL (which are set as described above), and USER and LOGNAME (which are set, even for the super-user, as described above), and set PATH to a compiled-in default value. Change to user’s home directory. Prepend ‘-’ to the shell’s name, intended to make it read its login startup file(s).

    • who : 시스템에 있는 사람을 보여줌

    • Whoami : 실행되고있는 유저를 보여줌

    • sudo : 특정 유저에게 특권 부여하기

    • last

  • sudoers

    • /etc/sudoers는 권한을 정리한파일

      #UserSpecificationSyntaxAccount Host=Command 
      root ALL=(ALL:ALL) ALL
      #user1 has root privilege while running “useradd”
      user1 ALL=/user/sbin/useradd
          
      #Members of group admin do not need a password 
      %admin ALL=NOPASSWD: ALL
      #Members of the sudo group may gain root privileges
      %sudo ALL=(ALL:ALL) ALL
      #Add users to group “admin” or “sudo” to make them sudoers.
      

      위 단락은 유저에 대한 권한. 아래단락은 그룹에 대한 권한을 나타낸다.

      %admin ALL=NOPASSWD: ALL
      >  admin 그룹은 sudo커맨드를쓸때 비밀번호를 칠필요가없이 실행가능함을 의미한다.
          
      user1 ALL=/user/sbin/useradd
      > 모든 호스트에 대해서 useradd 명령어를 사용가능하다.
          
      

그룹

  • /etc/group 파일로 관리
  • group은 그룹멤버들에게 같은 특권을 부여한다:
    • 즉 유저에게 sudoers그룹을 부여함으로써 권한부여가능

Adding a user

useradd command

리눅스는 유저를 uid로 구분함, 즉 uid가 같은 2 아디가있으면 리눅스는 똑같이 취급함.

Adding user means : 단지 숫자와 유저이름을 매핑시키는것.

shell은 취향임, 기본이 /bin/sh, 서버버전은 어차피 기본 shell밖에 없음.

default디렉토리 : 유저이름

로그인하면 > 리눅스는 userpw, shadow파일 두개보고 아이디 비번 체크해서 사용하게 허가.

- “useradd peterpan -m -s /bin/bash -G defender,neverland”

peterpan 유저를 설정하고, 설정파일에 정의된 경로를 홈디렉토리로 한다. bash를 기본 shell로 사용하고, 이 유저를 defender와, neverland그룹의 멤버로한다.

– Parameters for adding a new user

  • -m : creating the user home directory (/home/[username])
  • -g [default_group] : defining the group name of the user’s default login group
  • –G [supplementary_groups] : introducing a list of supplementary groups which the user is also a member; each group is separated by comma
  • –p [password] : defining the default password
  • -d [home_directory] : defining the home directory
  • –s [login_shell] : defining the path and filename of user’s default login shell
  • –o : allow non-unique UID

  • “/etc/skel” directory

유저를 만들때 사용할 기본 설정들이 들어있음. (유저의 스켈레톤이라고 생각)

adduser command

더 쉽고 interactive함.

Modifying Users

usermod command

유저 정보 변경

usermod -a -G attacker hook
# hook의 보조그룹에 attacker를 추가한다.
usermode : 사용자 계정 속성 변경
# usermod [옵션] [계정명]

옵션 
-a append : Add the user to the supplementary group(s). Use only with the -G option.
-c comment : 사용자 이름 또는 정보
-d home_directory : 사용자 계정 홈 디렉토리 지정
-e expire_date : 사용자 계정 만기일 지정
-f inactive_time : 비활성 기간, 사영자의 계정 유효일 지정
-g initial_group : 기본 그룹 지정
-G groups : 추가 그룹 변경(보조그룹)
-s shell : 로그인 시 사용할 기본 쉘 지정 
-u uid : 사용자 계정 uid 생성
 -m move-home : 홈디렉토리 변경시, 새 홈딩렉토리로 파일 이동(-d 옵션하고만 사용할 수 있음)
-l : 사용자명 변경
-L : 사용자의 패스워드에 Lock을 걸어 로그인 제한

Managing User

userdel command

userdel -f : 다른곳에서 사용하던 관계없이 유저 삭제.

passed 명령어

유저의 비밀번호를 설정

shadow파일을 다룸

Managing Groups

groupadd

  • creates and adds a new group

  • -g : gid 부여

groupmod

  • changes name or GID

groupdel

  • 그룹 번호삭제

유저와 매핑 삭제가 전부임

gpasswd

  • 그룹 비밀번호 설정
  • 유저 패스워드 입력 하다가 초기화시 ctrl + U

newgrp

  • 그룹 권한 변환

    내가 시스템상에 그 그룹에 포함안됬는데, 이 프로그램 실행돈안 잠시 그 그룹인척 할수있음. 그룹 구성원으로 바껴서 뭔가 액션을 할 수 있음.

    ex) 내가 다른그룹의 무언갈 사용할 필요가 있을때, 새 그룹 만들어서 그 파일에 대한 권한만 부여해놓고 그 그룹을 그 파일쓸때마다 가져와서 사용함.