Remotely execute commands under Linux system
rexec command is used to execute commands on the specified remote Linux system host and issue a request to execute the command to the remote rexec server.
The rexec command provides automatic login functionality by checking the $HOME/.netrc
file, which contains the username and password used on the remote host. If no such entry is found or the system is operating in secure mode (see the securetcpip command), the rexec command prompts for a valid username and password for the remote host. In both cases, rexec causes rexecd on the remote system to use the default compat user login authentication method. rexecd will not look for the /etc/security/user
file for alternate authentication methods. You can also specify the -n
flag on the rexec command line to reset the automatic login function.
rexec(options)(parameters)
-a: Indicates that the standard error of the remote command is the same as the standard output, and does not support sending arbitrary signals to the remote process;
-l<username>: Specify the username to connect to the remote rexec server;
-p<password>: Specify the password to connect to the remote rexec server;
-n: Explicitly prompt for username and password.
To execute the date command on a remote host, enter:
rexec host1 date
The output of the date command is now displayed on the local system. In this example, the $HOME/.netrc
file on the local host contains the valid username and password on the remote host. If there is no valid entry in the remote host's $HOME/.netrc
file, you will be prompted for a login ID and password. After entering the required login information, the output of the date command is displayed on the local system.
To reset the automatic login feature and execute the date command on the remote host, enter:
rexec -nhost1 date
Enter your username and password when prompted, and the output of the date command is now displayed on your local system.
To list another user's directories on the remote host, enter:
rexec host1 ls -l /home/karen
The directory listing for the karen user on the remote host host1 is displayed on the local system.
If there is no valid entry in the remote host's $HOME/.netrc
file, you will be prompted for a login ID and password. After entering the required login information, the directory listing for the karen user on the remote host host1 is displayed on the local system.