---
name: "rcmdsh"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/rcmdsh"
---

# rcmdsh(3)

return a stream to a remote command without superuser

## NAME

**rcmdsh** – return a stream to a remote command without superuser

## SYNOPSIS

**#include \<unistd.h\>**

*int*\

**rcmdsh**(*char \*\*ahost*, *int inport*, *const char \*locuser*, *const char \*remuser*, *const char \*cmd*, *const char \*rshprog*);

## DESCRIPTION

The **rcmdsh**() function is used by normal users to execute a command on a remote machine using an authentication scheme based on reserved port numbers using [rshd(8)](/rshd/8.md) or the value of *rshprog* (if non-NULL).

The **rcmdsh**() function looks up the host *\*ahost* using [gethostbyname(3)](/gethostbyname/3.md), returning -1 if the host does not exist. Otherwise *\*ahost* is set to the standard name of the host and a connection is established to a server residing at the well-known Internet port “shell/tcp” (or whatever port is used by *rshprog*). The *inport* argument is ignored; it is only included to provide an interface similar to [rcmd(3)](/rcmd/3.md).

If the connection succeeds, a socket in the UNIX domain of type SOCK\_STREAM is returned to the caller, and given to the remote command as stdin, stdout, and stderr.

## RETURN VALUES

The **rcmdsh**() function returns a valid socket descriptor on success. Otherwise, -1 is returned and a diagnostic message is printed on the standard error.

## SEE ALSO

[rsh(1)](/rsh/1.md), [socketpair(2)](/socketpair/2.md), [rcmd(3)](/rcmd/3.md), [rshd(8)](/rshd/8.md)

## HISTORY

The **rcmdsh**() function first appeared in OpenBSD 2.0, and made its way into FreeBSD 4.6.

## BUGS

If [rsh(1)](/rsh/1.md) encounters an error, a file descriptor is still returned instead of -1.
