Ubuntu users, user group settings

Source: Internet
Author: User
Tags chmod
When you create a user, you need to specify a user group for the new user, and a workgroup with the same name as the user name is automatically generated if you do not specify a workgroup to which the user is a member. When creating a user User1, specify the workgroup users that it belongs to, for example: Useradd–g users user1

First, create users:

1. Use command Useradd

Example: Useradd user1--Create a user user1
Useradd–e 12/30/2009 user2--Create user2, specify expiration date 2009-12-30
The default UID of the user increases from 500 to 500, and the following as the system retention account, you can specify the UID,

Example: Useradd–u User3

2. Use the passwd command to set a password for a new user
Example: passwd user1
Note: Users who do not have password settings are not available.

3, order usermod Modify user account
Example: Change the user's User1 login name to U1,
Usermod–l U1 user1
Example: Add user user1 to the Users group,
Usermod–g Users User1


Example: Change the user user1 directory to/users/us1
Usermod–d/users/us1 user1

4, use the command userdel delete user account
Example: Deleting a user User2
Userdel User2
Example: Deleting a user user3 and deleting his working directory
Userdel–r User3

5. View user Information
ID Command view a user's UID and GID, for example: View user4 ID
ID user4
Finger command--you can view the user's home directory, start the shell, user name, address, phone, and other information
Example: Finger user4

Second, the user group:

6. Command Groupadd Create user group
Groupadd–g 888 Users
Create a group of users with a GID of 888

7, command gpasswd Add users to the group
Only root and group administrators can change the members of the group:
Example: Add User1 to the Users group
Gpasswd–a User1 users
Example: Put User1 out of the Users group
Gpasswd–d User1 users

8, the command groupmod modify the group
Groupmod–n User users modify group name user to users

9, Groupdel Delete Group
Groupdel Users Delete Group users

Like Ubuntu and windows, you can create or remove new users arbitrarily, Windows is simpler, Ubuntu needs to use commands, but not very cumbersome to operate, so I try to write more detailed.

How to create an Ubuntu new user.

First open the terminal, input: sudo adduser username, the system will prompt the following information:

Adding user "username" ...

Adding new Group "username" (1001) ...

Adding new user "username" (1001) to group "username" ...

Create the home directory "/home/username" ...

Copying files from "/etc, Skel" ...

Enter a new UNIX password: (note here, instead of entering your current user's password, enter the password you want to create a new user)

Re-enter the new UNIX password: (Lose again)

passwd: Password was updated successfully

Changing the user information for username
Enter the new value, or press ENTER for the default
Full name []: Yangyang (Enter the name of the new user)
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is this information correct? [y/n] Y

To this step, the new user has been added successfully, at this time we can play ls/home view, if the display username Yang, the side on behalf of the user to create success.

How to remove an Ubuntu user.

Ubuntu Delete users also operate under the terminal, it should be noted that if the user to be deleted is currently logged in, is deleted, you must log off the current user to switch to another user to delete. For example, just now I have a new user for Yang, for example, I now use the user Yang landing the desktop, at this time if I want to delete yang this user, is deleted. The correct way to do this is to log off Yang and then use root to log on to the desktop, and then remove Yang.

Removing commands from Ubuntu users is easier to remember: sudo userdel username, for example, I want to remove Yang, then enter: sudo Userdel Yang, after the deletion of success, the system has no hint.

After you add a group, sudo cannot use the $sudo usermod-g test shared
Surfing the internet to see that it was not me who made this mistake ah. Posted as follows
<!--m-->http://hi.baidu.com/avauntage/blog/item ... ecbaf.html <!--m-->
Ubuntu sudoers2007 April 17 Tuesday 11:35 To install VBox, you need to add yourself to the Vboxusers group, find out with usermod command.
So:
$ sudo usermod-g vboxusers avauntage
Then, I find that I can no longer use sudo command. said that I was not in the/etc/sudoers. What is this stuff about? I've never been in touch. So I wanted to see:
$ cat/etc/sudoers
Found that there was no authority to look at this file. There's really nothing that can be done now. Without sudo, it's really impossible to do in Ubuntu.
A search on the internet, found that a lot of people so confused in the, and even more, incredibly ideas to reload the system.
Think of entering recovery mode, see that kind of root@avauntage, really have a brighter feeling.
This time looked at the/etc/sudoers:

#/etc/sudoers
#
# This file must is edited with the ' Visudo ' command as root.
#
# to the ' man ' page for details ' and ' to write a sudoers file.
#

# Host alias Specification

# User alias Specification

# CMND alias Specification

# Defaults

Defaults!lecture,tty_tickets,!fqdn

# User Privilege Specification
Root all= (All)

# members of the admin group may gain root privileges
%admin all= (All)

Find that you need to add yourself to the Admin group to use sudo. The original $ sudo usermod-g vboxusers avauntage command Just added itself to a group, the correct usage should be $ sudo usermod-ag vboxusers avauntage,-a means append. Usermod will remove the user from all groups before adding to the list of groups specified in the-G parameter. This design ...
Reboot, found that the sound card is not available, is definitely a problem with the group, so put yourself into the group to join:
sudo usermod-ag adm,dialout,dip,fax,cdrom,floppy,tape,audio,plugdev,scanner avauntage
Reboot again, all normal ~

This is often the case, and you want some users to have the right to restart Apache, and do not want to give them all permissions, this can be done through the user group.

First set up a user group WebAdmin:
sudo groupadd WebAdmin

Then add the appropriate users to the user group:
sudo usermod-g webadmin User name

Then edit sudo configuration:
sudo visudo

Add a sentence below
%webadmin all= (root)/etc/init.d/apache2 restart

This allows users in the WebAdmin group to have sudo privileges to restart Apache only.

Modified/etc/sudoers Permission 0777 (originally 0440)
cannot be used when SU root is not logged in: (chmod 0440/etc/sudoers) command to modify sudo permissions? Ubuntu root is prohibited by default and does not require you to set the root password at installation time, and the Red Hat system series is different here. To use, set the password for root, sudo passwd root:r2 I0 w/x5 T6 z "T4 ~ 
If only the common user password is forgotten, you can modify it with root. If root is forgotten, enter Single-user mode, which is also different from the Red Hat system series. &NBSP
Enter Single-user mode: 1, when the boot to grub, with the up and down key to move to the second line of the recovery mode, press E (note not return) 2, the RO single into a RW one init=/bin/bash then press ctrl+x can enter Single-user mode, It's all right to go in. Execute: (chmod 0440/etc/sudoers), you can change the normal user password, you can also change the root password. Press Ctrl+alt+delete reboot (I tried to turn off the computer by command, no reboot, only this). Of course, if you know the root password, the ones that are in front of it are superfluous, you directly SU root under the terminal, and then type the password, as root can modify the/etc/sudoers file mode (chmod 0440/etc/ Sudoers)

Today a new normal user is added to the user group and the user does not have sudo permissions, so the sudo visudo is modified by sudo to give the normal user root privileges. Later I thought about whether I could change the access to the/etc/sudoers file to 777, and then edit the file directly. So I didn't want to do it. When the result was changed, he found himself digging a hole and blocking himself outside the sudo door. The
     /etc/sudoers is a sudo configuration file, and its properties must be 440. When I use sudo chmod 777/etc/sudoers to modify the access rights of sudoers files, sudo is no longer available. Again, you want to modify the access rights of the file sudoers through sudo chmod 440/etc/sudoers, or use sudo to prompt: sudo:/etc/sudoers is mode 0777, should be 0440. So I shut myself out of Sudo's door. It is impossible to cut to the root user through sudo su or sudo-i. You can also switch to root with Su root. This allows you to modify the access rights of the/etc/sudoers file. The problem is solved.

      later found a resolution on the sudoers file on the Internet, which is posted below.

Sudo is a tool that allows a system administrator to allow ordinary users to perform some or all of the root commands, such as HALT,REBOOT,SU and so on. This will not only reduce the root user login and management time, but also improve security. sudo is not a substitute for the shell, it is oriented to each command. There are several main features of it:
§sudo can restrict a user from running certain commands on a single host.
§sudo provides a wealth of logs detailing what each user has done. It can upload logs to a central host or log server.
§sudo uses a timestamp file to perform a similar "check-in" system. When the user invokes sudo and enters its password, the user obtains a 5-minute lifetime ticket (this value can be changed at compile time).
The §sudo profile is a sudoers file that allows the system administrator to centralize the administration of user permissions and the host used. The location of the default is/etc/sudoers, and the attribute must be 0411.
Edit configuration File command: Visudo
Default profile location:/etc/sudoers
[Root@localhost ~]# Cat/etc/sudoers
# sudoers file.
#
# This file must is edited with the ' Visudo ' command as root.
#
# and the Sudoers man page is for the details on how to write a sudoers file.
#
# Host alias Specification
# User alias Specification

# CMND alias Specification

# Defaults Specification

# Runas alias Specification

# User Privilege Specification
Root all= (All)

# Uncomment to allow people in group wheel to run all commands
#%wheel all= (All)

# Same thing without a password
#%wheel all= (All) Nopasswd:all

# Samples
#%users All=/sbin/mount/cdrom,/sbin/umount/cdrom
#%users Localhost=/sbin/shutdown-h Now
[Root@localhost ~]#

You can edit the sudoers configuration file with Visudo, but you can also do it directly by modifying the sudoers file, but before editing, it's a good idea to look at its sample.sudoers file, which has a fairly detailed example to refer to. &NBSP
# Part One: User-defined, dividing users into Fulltimers, parttimers, and webmasters categories. &NBSP
User_alias fulltimers = Millert, Mikef, dowdy 
User_alias parttimers = Bostley, Jwfox, crawl 
User_alias webmasters = will, Wendy, wim 
# Part Two, sort the type of action. &NBSP
Runas_alias OP = root, operator 
Runas_alias DB = Oracle, SYBASE&NBSP,
#第三部分, categorizing hosts. These are all casually divided for the purpose of better management. &NBSP
Host_alias SPARC = bigtime, Eclipse, MOET, Anchor:/ 
SGI = Grolsch, Dandelion, Black:/ 
ALP HA = widget, thalamus, foobar:/ 
HPPA = Boa, nag, python 
Host_alias cunets =

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.