BASH - SSH Login?
Hey guys, I want to write my own script to rsync my files to my file server over SSH. I do not use authorized keys, I just prefer the warm cuddly feeling of a username and password authentication. So my question is how can I create an SSH session with my file server via a BASH Script?
Here are some details: My Desktop IP: Static, 10.1.1.20 HOSTNAME: debian My File Server IP: Static, 10.1.1.21 HOSTNAME: S-FSXX01 |
in /etc/sshd_config, change PubkeyAuthentication to no and PasswordAuthentication to yes.
|
My SSH works fine. I can do SSH, my question is how can I initiate the SSH session automatically via a BASH script?
|
Do you have to use Bash script? If you use Perl, there is a SSH module you can take advantage of.
|
Do you mean you want to run a script, then have it ssh? That's very easy.
create a file for the script: touch script.sh make it executable: chmod +x script.sh edit it: vi script.sh add this to it: ssh username@servername rsync <command stuffs here> exit you could further expand it by just using the rsync command in the initial SSH command.... like so: ssh username@servername "rsynch <commands>" |
So, hawk_0, where do you put in your password?
|
what is wrong with straight rsync?
or scp for that matter if you want security? Code:
#!/bin/bash Take your pick and you have a one-liner script that does what you need! infact you can even adapt that to take the args on command line for portability: Code:
#!/bin/bash Code:
#!/bin/bash You can then call the script like this: Code:
$ remote_trans.sh someuser somehost '/repote/path/*' '/local/path' |
I don't have to use Bash, but I would prefer to since I am trying to improve my bash scripting skills. I could do it with expect if needed, but I would need to hard code the password.
I guess I am trying to figure out a way to initiate an SSH session using password authentication, without user interaction, have the script do whatever it is going to do, and then terminate the SSH session. In this case I want to rsync some files to have it automate a differential flat file back up. I have the destination mounted using NFS, so in theory I could just do a copy, which is how I do it now, but I do it manually. I could script it to be automated using cp, but that just avoids me learning how to initiate the SSH session and using rsync. |
Quote:
|
Quote:
Code:
#!/bin/bash remote_trans.sh somehost '/repote/path/*' '/local/path' |
I had a feeling I was going to have to use expect to do this. I have never used expect so that adds to my learning curve.
|
If you don't mind me asking what is your issue with ssh keys?
It has been my experience that if done properly they are a nice (secure) tool. No one can shoulder surf your password and you can lock down the ssh server to only allow keys, this way nobody can brute force your ssh server passwords either. On the other hand if you are not in the habit of locking your own terminal, anyone can ssh without password to the remote server as well as having access to your terminal. |
you want ssh-agent
|
No GooseYArd worm5252 doesn't hence my question... worm5252 does not want to use ssh keys at all (via ssh-agent or not).
My question is still (if you do not mind me asking worm5252), why not? |
no i mean, he wants it , he just doesn't know that he wants it yet. these situations are precisely why ssh-agent exists. :)
|
All times are GMT -5. The time now is 09:17 PM. |