{"action":"opened","issue":{"url":"https://api.github.com/repos/isLishude/blog/issues/163","repository_url":"https://api.github.com/repos/isLishude/blog","labels_url":"https://api.github.com/repos/isLishude/blog/issues/163/labels{/name}","comments_url":"https://api.github.com/repos/isLishude/blog/issues/163/comments","events_url":"https://api.github.com/repos/isLishude/blog/issues/163/events","html_url":"https://github.com/isLishude/blog/issues/163","id":306143058,"number":163,"title":"Ubuntu新建用户并赋予权限清单","user":{"login":"isLishude","id":24730006,"avatar_url":"https://avatars1.githubusercontent.com/u/24730006?v=4","gravatar_id":"","url":"https://api.github.com/users/isLishude","html_url":"https://github.com/isLishude","followers_url":"https://api.github.com/users/isLishude/followers","following_url":"https://api.github.com/users/isLishude/following{/other_user}","gists_url":"https://api.github.com/users/isLishude/gists{/gist_id}","starred_url":"https://api.github.com/users/isLishude/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isLishude/subscriptions","organizations_url":"https://api.github.com/users/isLishude/orgs","repos_url":"https://api.github.com/users/isLishude/repos","events_url":"https://api.github.com/users/isLishude/events{/privacy}","received_events_url":"https://api.github.com/users/isLishude/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-17T09:42:01Z","updated_at":"2018-03-17T09:42:01Z","closed_at":null,"author_association":"OWNER","body":"\r\n## 新建用户\r\n\r\n首先在建立一个用户家目录，一般建立在 `/home` 下，目录名一般就是用户名。\r\n\r\n`useradd -d HOME-DIR -s /bin/bash -c COMMET -G GOURP-NAME USER-NAME`\r\n\r\n`-d` 指示用户家目录，`-s` 指定 shell， `-G` 指定用户组，`-c` 指定注释，最后再加上用户名称即可。详细的参数在文后有说明。\r\n\r\n值得注意的是 `-p` 可以指定登录密码，但是我尝试过没有成功。\r\n\r\n还有一个方式指定密码，使用 `passwd USER-NAME` 即可。\r\n\r\n将用户放入用户组，除了在 `usermod -aG GROUP-NAME USER-NAME`。\r\n\r\n然后给用户家目录赋权\r\n\r\n```\r\nsudo chown -R user:group /home/user\r\nsudo chmod -R 770 /home/user\r\n```\r\n\r\n最后复制shell模板到家目录\r\n\r\n`sudo /etc/skel/.bashrc /home/user`\r\n\r\n## root 权限\r\n\r\n编辑 `/etc/sudoers` \r\n\r\n```conf\r\n# User privilege specification\r\nroot\tALL=(ALL:ALL) ALL\r\nuser  ALL=(ALL:ALL) ALL\r\n```\r\n\r\n之前提及过 usermod 可以把用户添加到用户组，在 `/etc/sudoers` 后有说明将用户添加 `sudo` 组就可以使用 `sudo` 命令获取管理权限，在 CentOS上通常是 wheel 组而不是 sudo 组。\r\n\r\n```conf\r\n# Allow members of group sudo to execute any command\r\n%sudo\tALL=(ALL:ALL) ALL\r\n```\r\n第一个“ALL”表示该规则适用于所有主机，第二个表示root用户可以像所有用户一样运行命令，第三个表示root用户可以像所有组一样运行命令，最后一个“ALL”表示这些规则适用于所有命令。详情可参考：https://www.digitalocean.com/community/tutorials/how-to-edit-the-sudoers-file-on-ubuntu-and-centos\r\n\r\n最后退出当前用户，重新使用新用户登录试一试吧！\r\n\r\n## useradd 命令清单\r\n\r\n<img width=\"649\" alt=\"2018-03-17 5 10 34\" src=\"https://user-images.githubusercontent.com/24730006/37553587-2ea56f52-2a06-11e8-82d7-d638abbfe5c9.png\">\r\n"}}
{"actor":{"display_login":"isLishude"}}