By default, Telnet server is disabled for security purposes in favor of SSH. However, you can enable Telnet for testing purposes or for legacy scripts.
First, install the necessary packages.
sudo apt-get install -y xinetd telnetd
We’ll need to configure the inetd
configuration. Using your favorite editor and with root permission, open up /etc/inetd.conf
. Unless you’ve modified this file, it will probably not exist or be pretty empty.
Add the following line to the end of the file and save it.
telnet stream tcp nowait telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd
Next, we’ll need to configure the xinetd
service. Again, using your favorite editor and with root permission, open up /etc/xinetd.conf
. And, again, unless you’ve modified this file, it will be pretty empty.
Add the following lines to the end of the file and save it.
# Simple configuration file for xinetd # # Some defaults, and include /etc/xinetd.d/ defaults { # Please note that you need a log_type line to be able to use log_on_success # and log_on_failure. The default is the following : # log_type = SYSLOG daemon info instances = 60 log_type = SYSLOG authpriv log_on_success = HOST PID log_on_failure = HOST cps = 25 30 }
You can change telnet port number by editing /etc/services
with this line:
telnet 23/tcp
If you’d like to update the default configuration, edit /etc/xinetd.d/telnet
and add the following:
# default on # description: The telnet server serves telnet sessions; it uses # unencrypted username/password pairs for authentication. service telnet { disable = no flags = REUSE socket_type = stream wait = no user = root server = /usr/sbin/in.telnetd log_on_failure += USERID }
and for extra security you can add these lines as you like:
only_from = 192.168.120.0/24 # Only users in 192.168.120.0 can access only_from = .testy.com # Only allow access from testy.com no_access = 192.168.120.{101,105} # Do not allow access from these two IPs access_times = 8:00-9:00 20:00-21:00 # Only allow access during these two time windows
Finally, use the following command to start the telnet server:
sudo /etc/init.d/xinetd restart
Now, to test that it’s running properly:
ss -tnlp
If successful, you should see the telnet server running on port 23 (or whichever port you chose, if you configured something different above).
Nice. Works
Great!
For latest ubuntu, you also have to “apt install tcpd”