LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 01-12-2017, 09:17 AM   #1
Doc_doggo
LQ Newbie
 
Registered: Jan 2017
Posts: 4

Rep: Reputation: Disabled
problems logging with telnet


hello people, i am having a problem logging into a remote server using an expect script.

More specifically i am using said script to log in a server via ssh, that part is successful, but once connected to the first server i try to connect to another pc via telnet and the connection times out, the curiosity is if i replicate the whole process manually (i.e. i am the one typing all the commands) the telnet works, i will put here a copy of the scrip (due to security reasons all sensitive information was altered)


Code:
#!/usr/bin/expect -f
 
set timeout 180

expect "$"

spawn ssh moon_moon@ge.ne.ric.ip
expect "moon_moon@ge.ne.ric.ip's password: "
send "who_invited_moon_moon\r"

expect "Your option is: "

send "0\r"

expect "$ "
spawn date
expect "$ "

spawn telnet a.no.ther.ip

expect "Trying a.no.ther.ip... "

expect "*username: "
#send "moon_moon\r"
#expect "password: "
#send "who_invited_moon_moon\r"
#expect "# "
##send "instructions"
#expect "# "
#send "instructions"

#interact
so when i run this script the terminal freezes showing this
spawn telnet a.no.ther.ip
Trying a.no.ther.ip...

thank you all in advance
 
Old 01-12-2017, 09:38 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,305
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
Welcome.

I would very much avoid using expect and use keys for authentication. It's both difficult and unsafe. Either RSA or Ed25519 keys will work. Keys are safer and easy.

With key-based authentication, you'll be able to do it in one line:

Code:
ssh -i ~/.ssh/a_key_rsa -t moon_moon@ge.ne.ric.ip 'telnet a.no.ther.ip'
Additionally, once it's working, you can set the key so that it can only execute that one command.

Along the same lines, telnet as a protocol was deprecated in the 1990's. It's now 2017, there should be a high priority made on getting rid of it now.
 
1 members found this post helpful.
Old 01-12-2017, 09:54 AM   #3
Doc_doggo
LQ Newbie
 
Registered: Jan 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
first of all thak you Turbocapitalist for the help it worked like a charm
 
Old 01-12-2017, 10:08 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,305
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
No worries.

On the machine ge.ne.ric.ip in the account for moon_moon, you can modify the public key so that the key can only run telnet to a.no.ther.ip and nothing else.

If you have the default location for authorized_keys file on ge.ne.ric.ip you can find the public key and prepend command="" to it. That way it will run the designated command automatically and nothing else will be possible with that key.

Code:
command="/usr/bin/telnet a.no.ther.ip" ssh-ed25519 AAAAC3…
# or 
command="/usr/bin/telnet a.no.ther.ip" ssh-rsa AAAAC3…
The full description of the authorized_keys file format is in the manual page for sshd
 
1 members found this post helpful.
Old 01-12-2017, 12:22 PM   #5
Doc_doggo
LQ Newbie
 
Registered: Jan 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
No worries.

On the machine ge.ne.ric.ip in the account for moon_moon, you can modify the public key so that the key can only run telnet to a.no.ther.ip and nothing else.

If you have the default location for authorized_keys file on ge.ne.ric.ip you can find the public key and prepend command="" to it. That way it will run the designated command automatically and nothing else will be possible with that key.

Code:
command="/usr/bin/telnet a.no.ther.ip" ssh-ed25519 AAAAC3…
# or 
command="/usr/bin/telnet a.no.ther.ip" ssh-rsa AAAAC3…
The full description of the authorized_keys file format is in the manual page for sshd
once again thaks for the info, but one mor question were i to need to connect to many pc's can i make something like this

Code:
command="/usr/bin/telnet a.no.ther.ip" ssh-rsa AAAAC3…
command="/usr/bin/telnet a.no.ther.ip2" ssh-rsa AAAAC3…
.
.
.
and one last question what does the AAAc3 stands for?
once more thanks and sorry for the inconvenience

Last edited by Doc_doggo; 01-12-2017 at 01:29 PM.
 
Old 01-18-2017, 05:40 PM   #6
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 363Reputation: 363Reputation: 363Reputation: 363
>what does the AAAc3 stands for?

I got 'tripped' on this too, *until* I noticed the 3dots elipsis in prior posts: AAAc3...
Then I found a man page here with an example using AAAc...: (formatting 'broken' in that page too!)

An example authorized_keys file:

# Comments allowed at start of line
ssh-rsa AAAAB3Nza...LiPk== user@example.net
from="*.sales.example.net,!pc.sales.example.net" ssh-rsa
AAAAB2...19Q== john@example.net
command="dump /home",no-pty,no-port-forwarding ssh-dss
AAAAC3...51R== example.net

So, it's just a *random example* key, like filename [MYname] vs. filename [as a keyword]!
 
Old 01-18-2017, 11:56 PM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,305
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
Quote:
Originally Posted by Doc_doggo View Post
once again thaks for the info, but one mor question were i to need to connect to many pc's can i make something like this

Code:
command="/usr/bin/telnet a.no.ther.ip" ssh-rsa AAAAC3…
command="/usr/bin/telnet a.no.ther.ip2" ssh-rsa AAAAC3…
.
.
.
(Sorry I missed seeing the reply.)

You can make as many keys as you need and put them in the bastion host's / jump host's authorized_keys file. If there is a limit on the number of keys, it is quite high. Each key can be customized with a command="" to launch telnet. Again, you still want to get rid of the telnet servers as soon as possible. If you can't run full-blown OpenSSH, you can try Dropbear, which is modular.

However, there is a low limit on the number of keys ssh-agent can effectively use on the client you are connecting from to the bastion host / jump host. You can get around that limit by making shortcuts in ~/.ssh/config for each targeted telnet server that include IdentitiesOnly and the appropriate IdentityFile entry.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to switch off radio of waln0 of my router after telnet logging to it plotino Linux - Networking 6 09-22-2014 01:59 AM
Telnet logging hijack204 Linux - Enterprise 2 10-29-2008 11:34 AM
Problems logging in over telnet from a remote host ArcticFoxPaws Linux - Server 1 02-05-2007 04:00 PM
Logging telnet sessions Cynric Linux - General 2 08-14-2004 01:39 AM
telnet refuses logging in as root Racso Linux - Networking 6 07-08-2002 06:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 07:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration