rpcclient Command in Linux



The rpcclient command in Linux is a versatile tool used to interact with Windows NT servers and Samba servers. It allows administrators to perform various administrative tasks, such as managing user accounts, shares, and services, by sending RPC (Remote Procedure Call) requests to the server.

The rpcclient command is essential for system administrators who need to manage Windows and Samba servers from a Linux environment.

Table of Contents

Here is a comprehensive guide to the options available with the rpcclient command −

Understanding rpcclient Command

By using rpcclient, administrators can connect to remote hosts, authenticate using different mechanisms, and execute a wide range of commands to manage and troubleshoot Windows-based systems. This command is particularly useful for debugging and testing purposes, as well as for automating common administrative tasks through scripting.

Let’s install it −

sudo apt install smbclient
rpcclient Command in Linux1

The rpcclient command provides a command-line interface to execute RPC calls on a remote server. It can be used to query information, manage user accounts, and perform other administrative tasks.

Syntax of rpcclient Command

The basic syntax of the rpcclient command is as follows −

rpcclient [options] [server]

Where,

  • options − Various options to control the behavior of the command.
  • server − The hostname or IP address of the remote server.

rpcclient Command Options

Here are some commonly used options with the rpcclient command −

Options Description
-U username%password Specify the username and password for authentication.
-N Use anonymous login.
-c command Execute a single command and exit.
-d level Set the debug level.
-I ip Specify the IP address of the server.
-W workgroup Specify the workgroup or domain.

Examples of rpcclient Command in Linux

Let's explore some examples of using the rpcclient command with detailed explanations.

  • Connecting to a Remote Server
  • Querying Server Information
  • Listing User Accounts
  • Adding a New User Account
  • Deleting a User Account
  • Listing Shares
  • Adding a New Share
  • Deleting a Share
  • Querying Group Information
  • Adding a User to a Group

Connecting to a Remote Server

To connect to a remote server using the rpcclient command, use the following syntax −

rpcclient -U username%password server
rpcclient Command in Linux2

Replace username and password with the appropriate credentials and server with the hostname or IP address of the remote server. This command establishes a connection to the remote server.

Querying Server Information

Once connected to the remote server, you can query various types of information. For example, to query the server's domain information, use the following command −

rpcclient $> querydominfo
rpcclient Command in Linux3

This command retrieves and displays information about the server's domain, such as the domain name, domain SID, and number of users.

Listing User Accounts

To list all user accounts on the remote server, use the following command −

rpcclient $> enumdomusers
rpcclient Command in Linux4

This command retrieves and displays a list of all user accounts in the server's domain.

Adding a New User Account

To add a new user account on the remote server, use the following command −

rpcclient $> createuser newuser -U username%password
rpcclient Command in Linux5

Replace newuser with the desired username for the new account. This command creates a new user account on the remote server.

Deleting a User Account

To delete a user account on the remote server, use the following command −

rpcclient $> deleteuser olduser -U username%password
rpcclient Command in Linux6

Replace olduser with the username of the account to be deleted. This command removes the specified user account from the remote server.

Listing Shares

To list all shared resources on the remote server, use the following command −

rpcclient $> netshareenumall
rpcclient Command in Linux7

This command retrieves and displays a list of all shared resources, such as shared folders and printers, on the remote server.

Adding a New Share

To add a new shared folder on the remote server, use the following command −

rpcclient $> netshareadd sharename path -U username%password
rpcclient Command in Linux8

Replace sharename with the desired name for the new share and path with the path to the folder to be shared. This command creates a new shared folder on the remote server.

Deleting a Share

To delete a shared folder on the remote server, use the following command −

rpcclient $> netsharedelete sharename -U username%password
rpcclient Command in Linux9

Replace sharename with the name of the share to be deleted. This command removes the specified shared folder from the remote server.

Querying Group Information

To query information about a specific group on the remote server, use the following command −

rpcclient $> querygroup groupname
rpcclient Command in Linux10

Replace groupname with the name of the group to be queried. This command retrieves and displays information about the specified group, such as the group SID and list of members.

Adding a User to a Group

To add a user to a group on the remote server, use the following command −

rpcclient $> addusertogroup username groupname -U username%password
rpcclient Command in Linux11

Replace username with the name of the user to be added and groupname with the name of the group. This command adds the specified user to the specified group on the remote server.

Using rpcclient with Scripts

You can automate the use of rpcclient in shell scripts to perform batch operations on remote servers. For example, you can create a script to add multiple user accounts to a remote server −

#!/bin/

# List of new user accounts
users=("user1" "user2" "user3")

# Remote server credentials
server="remote_server"
username="admin"
password="password"

 #Add each user account
for user in "${users[@]}"; do
	rpcclient -U $username%$password $server -c "createuser $user"
done

This script adds the specified user accounts to the remote server.

Debugging of rpcclient Command

You can use the -d option to set the debug level and obtain more detailed output for troubleshooting. For example, to set the debug level to 3, use the following command −

rpcclient -U username%password -d 3 server
rpcclient Command in Linux12

This command provides more detailed output, which can be useful for diagnosing issues with RPC commands.

Conclusion

The rpcclient command is a versatile and powerful tool for managing Windows NT and Samba servers from a Linux environment. By understanding its various options and how to use them, you can effectively perform administrative tasks, query information, and manage user accounts and shares on remote servers.

Whether you're a system administrator or a network engineer, mastering the rpcclient command will enhance your ability to manage and maintain Windows and Samba servers efficiently.

Advertisements