02-06 06:35
Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Archives
관리 메뉴

기록을 합시다.

[Ubuntu] 사용자 관련 명령어 본문

공부/etc

[Ubuntu] 사용자 관련 명령어

울집고양이세마리 2023. 7. 21. 18:44

 

whoami 명령어 : 현재 사용자가 로그인한 계정을 보여줌

telemain1@danhee:~$ whoami
telemain1

w 명령어 : 접속해 있는 사용자 정보 및 시스템 정보를 화면에 출력

telemain1@danhee:~$ w
 22:57:20 up  1:02,  0 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT

useradd 명령어 : 시스템에 새로운 사용자 계정 추가, 루트 권한 필요

  • m 옵션 : 사용자 계정 추가 및 홈 디렉터리 생성(home/niniz 같은 거)
telemain1@danhee:~$ sudo useradd -m niniz [sudo] password for telemain1:
telemain1@danhee:~$ ls
telemain1@danhee:~$ pwd /home/telemain1
telemain1@danhee:~$ cd ..
telemain1@danhee:/home$
  • /etc/passwd : /etc/passwd 파일에서 사용자 계정 목록 확인 가능
telemain1@danhee:/home$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
telemain1:x:1000:1000:,,,:/home/telemain1:/bin/bash
niniz:x:1001:1002::/home/niniz:/bin/sh

passwd 명령어 : 사용자의 비밀번호를 바꿈

telemain1@danhee:/home$ sudo passwd niniz
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

adduser 명령어 : useradd 명령어를 사용한 뒤에, passwd 명령어를 사용한 것과 같음

telemain1@danhee:/home$ sudo adduser niniz2
[sudo] password for telemain1:
Adding user `niniz2' ...
Adding new group `niniz2' (1003) ...
Adding new user `niniz2' (1002) with group `niniz2' ...
Creating home directory `/home/niniz2' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for niniz2
Enter the new value, or press ENTER for the default
        Full Name []: niniz2 is a great user i've ever seen
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] y

userdel 명령어 : 사용자 계정 삭제 명령

telemain1@danhee:/home$ sudo userdel -r niniz

사용자 계정 전환

sudo를 실행할 수 있는 권한은 sudo 설정 파일인 /etc/sudoers에서 지정.

telemain1@danhee:/home$ sudo cat /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

su 명령어 : 사용자 계정을 전환하는 명령어

telemain1@danhee:/home$ su - niniz
Password:
tedious@danhee:~$ whoami
niniz
niniz@danhee:~$ sudo apt update
[sudo] password for niniz:
niniz is not in the sudoers file.  This incident will be reported.

exit 명령어 : su 명령 이전 사용자 계정으로 돌아감

niniz@danhee:~$ exit
logout

groupadd 명령어 : 새로운 그룹을 생성하는 명령어(루트 권한 필요)

telemain1@danhee:/home$ sudo groupadd ninizs
[sudo] password for telemain1:
telemain1@danhee:/home$ sudo adduser niniz
Adding user `niniz' ...
Adding new group `niniz' (1004) ...
Adding new user `niniz' (1002) with group `niniz' ...
Creating home directory `/home/niniz' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for niniz
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] y

gpasswd 명령어 : 그룹을 관리하는 명령어

telemain1@danhee:/home$ sudo gpasswd -a niniz ninizs
Adding user niniz to group ninizs

groups 명령어 : 사용자가 속해있는 그룹을 화면에 표시

telemain1@danhee:/home$ groups niniz
niniz : niniz ninizs
telemain1@danhee:/home$ groups telemain1
telemain1 : telemain1 adm dialout cdrom floppy sudo audio dip video plugdev netdev docker
telemain1@danhee:/home$ sudo gpasswd -d niniz ninizs
Removing user dizzy from group niniz

groupdel 명령어 : 그룹을 삭제하는 명령

telemain1@danhee:/home$ sudo groupdel ninizs
telemain1@danhee:/home$ groups
telemain1 adm dialout cdrom floppy sudo audio dip video plugdev netdev docker
Comments