GNU/Linux >> Linux の 問題 >  >> Linux

Linuxでidコマンドを使用する方法

idコマンドは、指定されたLinuxユーザーのIDを確認するために使用される基本的なLinuxコマンドです。また、LinuxのユーザーのUIDとGIDとともに、ユーザー名とグループ名を検索するためにも使用されます。デフォルトでは、idコマンドはすべてのLinuxオペレーティングシステムで使用できます。

この投稿では、Linuxでidコマンドを使用する方法を紹介します。

前提条件

  • Atlantic.Netクラウドプラットフォーム上の新しいUbuntu/CentOSサーバー
  • サーバーで構成されているrootパスワード

Atlantic.Netクラウドサーバーを作成する

まず、Atlantic.Netクラウドサーバーにログインします。 2GB以上のRAMを搭載したオペレーティングシステムとしてUbuntu/CentOSを選択して、新しいサーバーを作成します。 SSH経由でクラウドサーバーに接続し、ページの上部で強調表示されているクレデンシャルを使用してログインします。

Ubuntu / CentOSサーバーにログインしたら、次のコマンドを実行して、ベースシステムを最新の利用可能なパッケージで更新します。

apt-get update -y

または

yum update -y

基本構文

idコマンドを使用するための基本的な構文を以下に示します。

id [OPTIONS] [USERNAME]

次のコマンドですべてのオプションを印刷できます:

id --help

次の出力が表示されます。

Usage: id [OPTION]... [USERNAME]
Print user and group information for the specified USERNAME,
or (when USERNAME omitted) for the current user.

  -a              ignore, for compatibility with other versions
  -Z, --context   print only the security context of the current user
  -g, --group     print only the effective group ID
  -G, --groups    print all group IDs
  -n, --name      print a name instead of a number, for -ugG
  -r, --real      print the real ID instead of the effective ID, with -ugG
  -u, --user      print only the effective user ID
      --help     display this help and exit
      --version  output version information and exit

idコマンドの使用方法

オプションを指定せずにidコマンドを実行すると、現在のログインユーザーに関する情報が出力されます。

id

次の出力が表示されます。

uid=1000(username) gid=1000(username) groups=1000(username),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin),124(sambashare),125(vboxusers)

特定のユーザーのUIDのみを印刷するには、次のコマンドを実行します。

id -u username

出力:

1000

特定のユーザーのGIDのみを印刷するには、次のコマンドを実行します。

id -g username

出力:

1000

特定のユーザーのUIDとGIDを出力するには、次のコマンドを実行します。

id username

出力:

uid=1000(username) gid=1000(username) groups=1000(username),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin),124(sambashare),125(vboxusers)

ユーザーが属する他のすべてのグループのIDを出力するには、次のコマンドを実行します。

id -G username

出力:

1000 4 24 27 30 46 108 124 125

IDの代わりに名前を印刷するには、次のコマンドを実行します。

id -nG username

出力:

username adm cdrom sudo dip plugdev lpadmin sambashare vboxusers

有効なIDの代わりに実際のIDを表示するには、-rオプションを使用します:

id -r -u username

出力:

1000

または

id -r -g username

出力:

1000

または

id -r -G username

出力:

1000 4 24 27 30 46 108 124 125

結論

上記のガイドでは、idコマンドを使用してLinuxでユーザーIDとグループIDを検索する方法を学習しました。このコマンドは、アプリケーションでUIDまたはGIDを実行する必要がある場合に役立ちます。 Atlantic.NetVPSを試してみてください。


Linux
  1. Linuxsedコマンドの使用方法

  2. Linuxgrepコマンドの使用方法

  3. LinuxでSuコマンドを使用する方法

  1. Linuxでhistoryコマンドを使用する方法

  2. Linuxでsudoコマンドを使用する方法

  3. Linux で「screen」コマンドを使用する方法

  1. Linuxをコマンドで使用する方法

  2. Linuxでlocateコマンドを使用する方法

  3. Linuxの履歴コマンドの使用方法