I'm trying to write a C library that connects and talks to a robot which has a telnet server.

The server info is the following:

  • user: as
  • ip:
  • port: 23
  • it has no password

In the robot_init() function I'd like to connect to the robot, and I'd expect the following code to do it:

FILE *telnet = popen("telnet -l as 23", "w");

From man telnet:

     telnet [-468ELadr] [-S tos] [-b address] [-e escapechar] [-l user]
            [-n tracefile] [host [port]]

     -l user
             Specify user as the user to log in as on the remote system. This
             is accomplished by sending the specified name as the USER envi‐
             ronment variable, so it requires that the remote system support
             the TELNET NEW-ENVIRON option. This option implies the -a option,
             and may also be used with the open command.

However, before writing the C code, I tried to set up a telnet server in a docker container and talk to it through another docker as a client.

To run the server:

sudo docker container run --name telnet-server --publish 2323:23 --detach --restart unless-stopped secobau/telnetd:alpine-1.1

This server has user = user; ip =; port = 2323; and no password.

To run the client:

sudo docker run --interactive --tty --name=telnet-client debian:testing bash
apt-get update
apt-get install telnet --yes
telnet -l user 2323

I'd expect this to give me an already logged in telnet conection (or at least ask me for the password directly), but instead it keeps asking for a login.

Is it a bug in telnet? How should I automate this?

If telnet -l doesn't work I think I'll have to write through the pipe something like:

fprintf(telnet, "as\n");  // user
fprintf(telnet, "\n"); // password (no password)
  • apt-get install telnet --yes results in E: Unable to locate package telnet Feb 24, 2020 at 14:43
  • Ups, I forgot to copy the apt-get update line Feb 24, 2020 at 14:45

1 Answer 1


Interesting question, it shows how easy it is to quickly setup several different services completely isolated from each other with Docker.

I think that telnetd still asks for the password because it's stared with -l /bin/login on the server side as you can see in the Dockerfile for secobau/telnetd:alpine-1.1:

ARG LOGIN=/bin/login

ENV CMD "/usr/sbin/telnetd -p $PORT -b $ADDR -l $LOGIN -F"

You can create a very similar Dockerfile but replace /bin/login with /bin/sh and it would work. For example, new Dockerfile could be:

FROM alpine

ARG LOGIN=/bin/login

ENV CMD "/usr/sbin/telnetd -p $PORT -b $ADDR -l /bin/sh -F"


RUN apk update && apk upgrade && apk add busybox-extras
RUN adduser -D $USER && echo -e "\n\n" | passwd $USER

RUN echo "$CMD" | tee cmd.sh && chmod +x cmd.sh
CMD ./cmd.sh

Build it:

docker build -t my/telnet .

Run it:

docker container run --name my-telnet-server --publish 2323:23 --detach --restart unless-stopped  my/telnet

You now should be able to login w/o entering username and password from the client container:

root@e55f8f1f3e55:/# telnet -l user 2323
Connected to
Escape character is '^]'.

/ #

BTW, you don't have to run docker with sudo, just add yourself to docker group.

  • "BTW, you don't have to run docker with sudo, just add yourself to docker group.": Thanks, I didn't know Feb 24, 2020 at 15:06
  • I still have a problem. I then can't log in as "user": # telnet -l user 2323 Trying Connected to Escape character is '^]'. / # whoami root / # Feb 24, 2020 at 15:27
  • @CacahueteFrito: indeed, it doesn't work. Sorry. I'm not sure it's possible to achieve that with busybox telnetd implementation. Feb 24, 2020 at 16:16
  • ok, then I'll just write the user and a blank line through the pipe, and maybe a usleep() before and after the password is asked. Feb 24, 2020 at 16:19
  • Can't you do su user after logging in as root? Feb 24, 2020 at 16:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .