1.20. Frequently used Samba command-line utilities
This chapter describes frequently used commands when working with a Samba server.
1.20.1. Using the net ads join and net rpc join commands 링크 복사링크가 클립보드에 복사되었습니다!
Using the join subcommand of the net utility, you can join Samba to an AD or NT4 domain. To join the domain, you must create the /etc/samba/smb.conf file manually, and optionally update additional configurations, such as PAM.
Red Hat recommends using the realm utility to join a domain. The realm utility automatically updates all involved configuration files.
Procedure
Manually create the
/etc/samba/smb.conffile with the following settings:For an AD domain member:
[global] workgroup = domain_name security = ads passdb backend = tdbsam realm = AD_REALMFor an NT4 domain member:
[global] workgroup = domain_name security = user passdb backend = tdbsam
-
Add an ID mapping configuration for the
*default domain and for the domain you want to join to the[global] section in the/etc/samba/smb.conffile. Verify the
/etc/samba/smb.conffile:# testparmJoin the domain as the domain administrator:
To join an AD domain:
# net ads join -U "DOMAIN\administrator"To join an NT4 domain:
# net rpc join -U "DOMAIN\administrator"
Append the
winbindsource to thepasswdandgroupdatabase entry in the/etc/nsswitch.conffile:passwd: files winbind group: files winbindEnable and start the
winbindservice:# systemctl enable --now winbindOptional: Configure PAM using the
authselectutility.For details, see the
authselect(8)man page on your system.Optional: For AD environments, configure the Kerberos client.
For details, see the documentation of your Kerberos client.
1.20.2. Using the net rpc rights command 링크 복사링크가 클립보드에 복사되었습니다!
In Windows, you can assign privileges to accounts and groups to perform special operations, such as setting ACLs on a share or upload printer drivers. On a Samba server, you can use the net rpc rights command to manage privileges.
Listing privileges you can set
To list all available privileges and their owners, use the net rpc rights list command. For example:
# net rpc rights list -U "DOMAIN\administrator"
Enter DOMAIN\administrator's password:
SeMachineAccountPrivilege Add machines to domain
SeTakeOwnershipPrivilege Take ownership of files or other objects
SeBackupPrivilege Back up files and directories
SeRestorePrivilege Restore files and directories
SeRemoteShutdownPrivilege Force shutdown from a remote system
SePrintOperatorPrivilege Manage printers
SeAddUsersPrivilege Add users and groups to the domain
SeDiskOperatorPrivilege Manage disk shares
SeSecurityPrivilege System security
Granting privileges
To grant a privilege to an account or group, use the net rpc rights grant command.
For example, grant the SePrintOperatorPrivilege privilege to the DOMAIN\printadmin group:
# net rpc rights grant "DOMAIN\printadmin" SePrintOperatorPrivilege -U "DOMAIN\administrator"
Enter DOMAIN\administrator's password:
Successfully granted rights.
Revoking privileges
To revoke a privilege from an account or group, use the net rpc rights revoke command.
For example, to revoke the SePrintOperatorPrivilege privilege from the DOMAIN\printadmin group:
# net rpc rights remoke "DOMAIN\printadmin" SePrintOperatorPrivilege -U "DOMAIN\administrator"
Enter DOMAIN\administrator's password:
Successfully revoked rights.
1.20.4. Using the net user command 링크 복사링크가 클립보드에 복사되었습니다!
The net user command enables you to perform the following actions on an AD DC or NT4 PDC:
- List all user accounts
- Add users
- Remove Users
Specifying a connection method, such as ads for AD domains or rpc for NT4 domains, is only required when you list domain user accounts. Other user-related subcommands can auto-detect the connection method.
Pass the -U user_name parameter to the command to specify a user that is allowed to perform the requested action.
Listing domain user accounts
To list all users in an AD domain:
# net ads user -U "DOMAIN\administrator"
To list all users in an NT4 domain:
# net rpc user -U "DOMAIN\administrator"
Adding a user account to the domain
On a Samba domain member, you can use the net user add command to add a user account to the domain.
For example, add the user account to the domain:
Add the account:
# net user add user password -U "DOMAIN\administrator" User user addedOptional: Use the remote procedure call (RPC) shell to enable the account on the AD DC or NT4 PDC. For example:
# net rpc shell -U DOMAIN\administrator -S DC_or_PDC_name Talking to domain DOMAIN (S-1-5-21-1424831554-512457234-5642315751) net rpc> user edit disabled user: no Set user's disabled flag from [yes] to [no] net rpc> exit
Deleting a user account from the domain
On a Samba domain member, you can use the net user delete command to remove a user account from the domain.
For example, to remove the user account from the domain:
# net user delete user -U "DOMAIN\administrator"
User user deleted
1.20.5. Using the rpcclient utility 링크 복사링크가 클립보드에 복사되었습니다!
The rpcclient utility enables you to manually execute client-side Microsoft Remote Procedure Call (MS-RPC) functions on a local or remote SMB server. However, most of the features are integrated into separate utilities provided by Samba. Use rpcclient only for testing MS-PRC functions.
Prerequisites
-
The
samba-clientpackage is installed.
Procedure
You can use the
rpcclientutility to:Manage the printer Spool Subsystem (SPOOLSS) by assigning a driver to a printer:
# rpcclient server_name -U "DOMAIN\administrator" -c 'setdriver "printer_name" "driver_name"' Enter DOMAIN\administrators password: Successfully set printer_name to driver driver_name.Retrieve information about an SMB server by listing all file shares and shared printers:
# rpcclient server_name -U "DOMAIN\administrator" -c 'netshareenum' Enter DOMAIN\administrators password: netname: Example_Share remark: path: C:\srv\samba\example_share\ password: netname: Example_Printer remark: path: C:\var\spool\samba\ password:Perform actions using the Security Account Manager Remote (SAMR) protocol by listing Users on an SMB Server:
# rpcclient server_name -U "DOMAIN\administrator" -c 'enumdomusers' Enter DOMAIN\administrators password: user:[user1] rid:[0x3e8] user:[user2] rid:[0x3e9]If you run the command against a standalone server or a domain member, it lists the users in the local database. Running the command against an AD DC or NT4 PDC lists the domain users.
For more information, please see the
rpcclient(1)man page on your system.
1.20.6. Using the samba-regedit application 링크 복사링크가 클립보드에 복사되었습니다!
Certain settings, such as printer configurations, are stored in the registry on the Samba server. You can use the ncurses-based samba-regedit application to edit the registry of a Samba server.
Prerequisites
-
The
samba-clientpackage is installed.
Procedure
To start the application, enter:
# samba-regeditUse the following keys:
- Cursor up and cursor down: Navigate through the registry tree and the values.
- Enter: Opens a key or edits a value.
-
Tab: Switches between the
KeyandValuepane. - Ctrl+C: Closes the application.
1.20.7. Using the smbcontrol utility 링크 복사링크가 클립보드에 복사되었습니다!
The smbcontrol utility enables you to send command messages to the smbd, nmbd, winbindd, or all of these services. These control messages instruct the service, for example, to reload its configuration.
Prerequisites
-
The
samba-common-toolspackage is installed.
Procedure
Reload the configuration of the
smbd,nmbd,winbinddservices by sending thereload-configmessage type to thealldestination:# smbcontrol all reload-configFor more information, see the
smbcontrol(1)man page on your system.
1.20.8. Using the smbpasswd utility 링크 복사링크가 클립보드에 복사되었습니다!
The smbpasswd utility manages user accounts and passwords in the local Samba database. For more information, see the smbpasswd(8) man page on your system.
Prerequisites
-
The
samba-common-toolspackage is installed.
Procedure
If you run the command as a user,
smbpasswdchanges the Samba password of the user who run the command. For example:[user@server ~]$ smbpasswd New SMB password: password Retype new SMB password: passwordIf you run
smbpasswdas therootuser, you can use the utility, for example, to:Create a new user:
[root@server ~]# smbpasswd -a user_name New SMB password: password Retype new SMB password: password Added user user_name.참고Before you can add a user to the Samba database, you must create the account in the local operating system.
Enable a Samba user:
[root@server ~]# smbpasswd -e user_name Enabled user user_name.Disable a Samba user:
[root@server ~]# smbpasswd -x user_name Disabled user user_nameDelete a user:
[root@server ~]# smbpasswd -x user_name Deleted user user_name.
1.20.9. Using the smbstatus utility 링크 복사링크가 클립보드에 복사되었습니다!
The smbstatus utility reports on:
-
Connections per PID of each
smbddaemon to the Samba server. This report includes the user name, primary group, SMB protocol version, encryption, and signing information. -
Connections per Samba share. This report includes the PID of the
smbddaemon, the IP of the connecting machine, the time stamp when the connection was established, encryption, and signing information. - A list of locked files. The report entries include further details, such as opportunistic lock (oplock) types
Prerequisites
-
The
sambapackage is installed. -
The
smbdservice is running.
Procedure
Run the
smbstatusutility:# smbstatus Samba version 4.15.2 PID Username Group Machine Protocol Version Encryption Signing ....------------------------------------------------------------------------------------------------------------------------- 963 DOMAIN\administrator DOMAIN\domain users client-pc (ipv4:192.0.2.1:57786) SMB3_02 - AES-128-CMAC Service pid Machine Connected at Encryption Signing: ....--------------------------------------------------------------------------- example 969 192.0.2.1 Thu Nov 1 10:00:00 2018 CEST - AES-128-CMAC Locked files: Pid Uid DenyMode Access R/W Oplock SharePath Name Time ....-------------------------------------------------------------------------------------------------------- 969 10000 DENY_WRITE 0x120089 RDONLY LEASE(RWH) /srv/samba/example file.txt Thu Nov 1 10:00:00 2018For more information, see the
smbstatus(1)man page on your system.
1.20.10. Using the smbtar utility 링크 복사링크가 클립보드에 복사되었습니다!
The smbtar utility backs up the content of an SMB share or a subdirectory of it and stores the content in a tar archive. Alternatively, you can write the content to a tape device. For more information, see the smbtar(1) man page on your system.
Prerequisites
-
The
samba-clientpackage is installed.
Procedure
Use the following command to back up the content of the
demodirectory on the//server/example/share and store the content in the/root/example.tararchive:# smbtar -s server -x example -u user_name -p password -t /root/example.tar
1.20.11. Using the wbinfo utility 링크 복사링크가 클립보드에 복사되었습니다!
The wbinfo utility queries and returns information created and used by the winbindd service. For more information, see the wbinfo(1) man page on your system.
Prerequisites
-
The
samba-winbind-clientspackage is installed.
Procedure
You can use
wbinfo, for example, to:List domain users:
# wbinfo -u AD\administrator AD\guest ...List domain groups:
# wbinfo -g AD\domain computers AD\domain admins AD\domain users ...Display the SID of a user:
# wbinfo --name-to-sid="AD\administrator" S-1-5-21-1762709870-351891212-3141221786-500 SID_USER (1)Display information about domains and trusts:
# wbinfo --trusted-domains --verbose Domain Name DNS Domain Trust Type Transitive In Out BUILTIN None Yes Yes Yes server None Yes Yes Yes DOMAIN1 domain1.example.com None Yes Yes Yes DOMAIN2 domain2.example.com External No Yes Yes