Product SiteDocumentation Site

8.4. Usuário e grupo bancos de dados

A lista de usuários é normalmente armazenada no /etc/passwd, enquanto o /etc/shadow armazena senhas em hash. Ambos são arquivos de texto, em um formato relativamente simples, que podem ser lidos e modificados com um editor de texto. Cada usuário está listado lá em uma linha com vários campos separados por dois-pontos (“:”).

8.4.1. Lista de Usuários: /etc/passwd

Aqui está uma lista de campos do arquivo /etc/passwd:
  • login, por exemplo rhertzog;
  • password: this is a password encrypted by a one-way function (crypt), relying on DES, MD5, SHA-256 or SHA-512. The special value “x” indicates that the encrypted password is stored in /etc/shadow;
  • uid: identificar numérico único para cada usuário;
  • gid:número único para o grupo principal do usuário (O Debian cria, por padrão, um grupo específico para cada usuário);
  • GECOS: campo de dados contendo normalmente o nome completo de usuário;
  • diretório de login, atribuído ao usuário para armazenar arquivos pessoais (a variável de ambiente $HOME geralmente aponta para ele);
  • programa para executar no login. Em geral é um interpretador de comandos (shell), deixando o usuário com "rédea solta". Se você especificar /bin/false (que não faz nada e devolve o controle imediatamente), o usuário não vai conseguir fazer login.
As mentioned before, one can edit this file directly. But there are more elegant ways to apply changes, which are described in Seção 8.4.3, “Modificando uma Conta de Usuário Existente ou Senha”.

8.4.2. O Oculto e Criptografo Arquivo de Senhas: /etc/shadow

O arquivo /etc/shadow contém os seguintes campos:
  • login;
  • senha criptografada;
  • diversos campos controlam a expiração da senha.
One can expire passwords using this file or set the time until the account is disabled after the password has expired.

8.4.3. Modificando uma Conta de Usuário Existente ou Senha

The following commands allow modification of the information stored in specific fields of the user databases: passwd permits a regular user to change their password, which in turn, updates the /etc/shadow file (chpasswd allows administrators to update passwords for a list of users in batch mode); chfn (CHange Full Name), reserved for the super-user (root), modifies the GECOS field. chsh (CHange SHell) allows the user to change their login shell; however, available choices will be limited to those listed in /etc/shells; the administrator, on the other hand, is not bound by this restriction and can set the shell to any program of their choosing.
Finalmente, o comando chage (CHange AGE) permite ao administrador alterar as configurações de expiração da senha (a opção -l user irá listar as configurações corrente). Você também pode forçar a expiração da senha usando o comando passwd -e user, o qual irá requerer que o usuário altere sua senha na próxima vez que iniciar uma sessão.
Besides these tools the usermod command allows to modify all the details mentioned above.

8.4.4. Desabilitando uma Conta

You may find yourself needing to “disable an account” (lock out a user), as a disciplinary measure, for the purposes of an investigation, or simply in the event of a prolonged or definitive absence of a user. A disabled account means the user cannot login or gain access to the machine. The account remains intact on the machine and no files or data are deleted; it is simply inaccessible. This is accomplished by using the command passwd -l user (lock). Re-enabling the account is done in similar fashion, with the -u option (unlock). This, however, only prevents password-based logins by the user. The user might still be able to access the system using an SSH key (if configured). To prevent even this possibility you have to expire the account as well using either chage -E 1user or usermod -e 1 user (giving a value of -1 in either of these commands will reset the expiration date to never). To (temporarily) disable all user accounts just create the file /etc/nologin.
You can disable a user account not only by locking it as described above, but also by changing its default login shell (chsh -s shell user). With the latter changed to /usr/sbin/nologin, a user gets a polite message informing that a login is not possible, while /bin/false just exits while returning false. There is no switch to restore the previous shell. You have to get and keep that information before you change the setting. These shells are often used for system users which do not require any login availability.

8.4.5. Lista de Grupo: /etc/group

Grupos são listados no arquivo /etc/group, um banco de dados de texto simples em um formato similar ao arquivo /etc/passwd, com os seguintes campos:
  • nome do grupo;
  • senha (opcional): Isso só é usado para participar de um grupo quando não se é um membro usual (com os comandos newgrp ou sg, veja barra lateral DE VOLTA AO BÁSICO Trabalhando com grupos diversos);
  • gid: identificar numérico único para cada grupo;
  • lista de membros: lista de nomes de usuários que são membros do grupo, separados por vírgulas.
Os comandos addgroup e delgroup adicionam ou apagam um grupo, respectivamente. O comando groupmod modifica a informação do grupo (seu gid ou identificador). O comando gpasswdgrupo altera a senha para o grupo, enquanto o comando gpasswd -rgrupo o apaga.