LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   telnet login via shell script (https://www.linuxquestions.org/questions/linux-general-1/telnet-login-via-shell-script-20426/)

lethe 05-07-2002 03:53 PM

telnet login via shell script
 
is it possible for me to have a shell script log me in to a telnet session? i have in mind something along the lines of

% telnet host < script, where the first two lines of script will be username and pass followed by a list of commands to execute on the remote host.

this doesn t work as written, because telnet expects the login and pass to come from standard in, and won t seem to let me redirect.

any thoughts?

acid_kewpie 05-07-2002 04:05 PM

hmm, yes it is possible, but it is A VERY BAD THING TO DO AND SHOULD BE AVOIDED AT ALL COSTS.

but if you really insist, i think you go something like:

( echo $USER; sleep 1; echo $PASS; sleep 1; echo exit ) | telnet abc.com

lethe 05-10-2002 03:54 AM

why is it bad? i guess because people can read your password. if it is only in your head then no one can steal it, right?

growler 05-11-2002 06:58 AM

Quote:

Originally posted by lethe
why is it bad? i guess because people can read your password. if it is only in your head then no one can steal it, right?
ding! ding! that's it!

two issues: 1st, telnet sends all info as clear text, meaning someone using a packet sniffer can find out all the commands you typed using telnet - username, password, commands you executed, output of those commands, etc.; 2nd, your idea requires you to store your password in a file somewhere on your disk - also bad!

use ssh rather than telnet. it uses an encrypted data-stream.

you can also configure ssh to auto-magically accept the connection (passwordless logons), without sending the password, by copying your local authentication keys to your remote keyfile. this would be useful for your script idea.

unfortunately, that explanation would take a few pages, and I'd basically be plagiarizing the ssh chapter from Building Linux VPNs. Great book!

lethe 05-11-2002 10:15 PM

can you pipe commands to ssh? when i try it, it just exits, saying that stdin is not a terminal.

acid_kewpie 05-12-2002 04:41 AM

no, because it is again.. and EXTREMELY DUMB THING TO DO! :D ssh designers had the sense to not let it ever happen in the first place. security should always come first.

Hano 05-12-2002 10:37 AM

i understand that ssh doesn't allow to send the USER and PASS piped for security reasons, but, why it doesn't allow you to pipe commands directly? for now, the only way to do that that i'd found is:

set a passwordless login

then call
ssh -x host.org <command>

but this way has the disadvantage of closing the connection after finishing executing the <command> . There is no way to pipe commands from a script without having to close and reopen ssh for every new command??


Thanks in advance

Hano

Mik 05-13-2002 03:30 AM

Can't you place the script you want to run on the server and then do something like:

ssh -f hostname scriptname

Hano 05-13-2002 09:31 AM

yes, you can! but it closes the ssh connection after finishing. I would prefer a stream where you can pipe commands to the ssh without closing it.


Hano


All times are GMT -5. The time now is 07:57 PM.