Advertisement

Need help with basic Linux Shell Scripting

Started by May 29, 2007 02:38 PM
9 comments, last by Sander 17 years, 4 months ago
I am trying to do the following to make my work life easier... I am new to linux, but this is the shell script I am trying to write: (note: I modified the addresses and password for this example) ssh root@111.11.11.11 -X #SSH Server will now prompt for password #However I am inside SSH so I simply can't echo it. echo password ssh serverName@222.222.222.2 -X -i identification_key_file If it is impossible to shell script while inside a program, is there a way I can execute shell commands from a c/c++ program?
Anyone has any idea? I thought there were a multitude of linux gurus here.
Advertisement
hello,
look at execl function family or system function

Quote: Original post by Khaos Dragon
I am trying to do the following to make my work life easier...

I am new to linux, but this is the shell script I am trying to write:
(note: I modified the addresses and password for this example)

ssh root@111.11.11.11 -X
#SSH Server will now prompt for password
#However I am inside SSH so I simply can't echo it.
echo password
ssh serverName@222.222.222.2 -X -i identification_key_file

If it is impossible to shell script while inside a program, is there a way I can execute shell commands from a c/c++ program?


I am not really sure what your problem is, but maybe you want to exchange your ssh-keys, so you don't need to use your password every login?

save the publickey of your computer into the ~/.ssh/authorized_keys on your remotemachine. (this file may differ form system to system @see man ssh)

For executing stuff on the commandline use system(), or popen() (popen provides a pipe to the out or in of the called command, so you can for example read what "ls -l" says.
What are you trying to do? Log in via SSH using a script? Are RSA keys a viable option?

SSH login without password

It allows one computer with the right key to login to another without a password.

Edit: beaten, by a healthy margin too!
Quote: Original post by Khaos Dragon
Anyone has any idea? I thought there were a multitude of linux gurus here.

They're probably hanging around in the "Everything Unix"-forum [smile]

Advertisement
I am actually tunneling from one ssh server to another so flagging a key as a password for the first machine won't fix the issue. I will look at the execl function family and system function however.
Is there a way to write to a console, like perhaps:

WriteToConsole( int PidOfConsole, char* text );

?
Quote: Original post by Khaos Dragon
I am trying to do the following to make my work life easier...

I am new to linux, but this is the shell script I am trying to write:
(note: I modified the addresses and password for this example)

ssh root@111.11.11.11 -X
#SSH Server will now prompt for password
#However I am inside SSH so I simply can't echo it.
echo password
ssh serverName@222.222.222.2 -X -i identification_key_file

I am having difficulty understanding the problem. Let me guess what you're trying to do.

You're trying to write a shell script that will connect you to server 1 with an X tunnel, and from there connect you onwards to server 2 (again with an X tunnel). The first server prompts you for a password and you can't plop your own private key on the remote server as documented above, for some undisclosed reason.

Is your problem that you can't type in your password, or is your problem that you the second command does not get executed?

If your problem is the latter, try the following.
ssh -f -Y root@11.11.11.11 "ssh serverName@222.222.222.2 -X -i identification_key_file"

Of course, if you need to do more, you can always drop the -f switch and redirect stdin from a here document.

If the problem is that you can't have the shell script pass the password to ssh, that's because it a wide-open gaping security hole. If you want to use ssh without a password prompt, see above.

Oh, and yes it's possible to write a C program that will open a pseudotty for a forked ssh session, but that's not usually found in introductory courses on Unix systems programming. You'll need to man forkpty() and get to know execl() and select() and wait() pretty thoroughly.

Stephen M. Webb
Professional Free Software Developer

Moving to Everything Unix.

This topic is closed to new replies.

Advertisement