sshfs auto login

Red Squirrel

No Lifer
May 24, 2003
68,457
12,611
126
www.anyf.ca
I want to setup a backup job so I can backup my websites to my home server as right now I do it manually (for DB, uploaded files, that type of stuff - actual website data is already localized). Only issue is I can't seem to figure how to auto feed it the password.

This is shared hosting so I don't have access to the configuration to setup public key stuff and most shared hosts don't have public key as its more complex for users, password auth is still preferred. So any way to automate this?

Also is using this hard on the server at all or does it just look like a regular ssh session? I don't want my backups to bog down the server. It seems to be ok though.
 

sourceninja

Diamond Member
Mar 8, 2005
8,805
65
91
I've always just pasted my key in .ssh/authorized_keys and been done with it. I don't know how to do it without keys.
 

Red Squirrel

No Lifer
May 24, 2003
68,457
12,611
126
www.anyf.ca
Yeah for my own dedicated server thats a possible option as I can just set authentication to use keys, but on shared hosting its not really an option as it uses password authentication.

It's the same with the ssh command, I've never been able to find a way to make it auto login then execute a script remotely. That's going to be another of my requirements for my backups so I can auto backup my databases too. I realize its a security issue to have to store a password somewhere, but its not any different then storing a key. If someone gets on my server and gets access to the config that's a huge issue on it's own.
 

yoda291

Diamond Member
Aug 11, 2001
5,079
0
0
are you sure ssh keys aren't enabled? Most shared hosts will leave the default auth options open in my experience and maybe disable gss and sshv1 IME. Also, just to cover the small possibility, you have tried putting your public key in ~/.ssh/authorized_keys2 as opposed to authorized_keys?

In any event, you could use an expect script to feed the password across for the mount. this would rule out using fstab, but you could always drop your script into rc.local.
 

Red Squirrel

No Lifer
May 24, 2003
68,457
12,611
126
www.anyf.ca
Hmm so would it be possible that keys And password authentication are used? If yes how do I go about disabling the password authentication and use just keys? (on the shared host)
 

yoda291

Diamond Member
Aug 11, 2001
5,079
0
0
Originally posted by: RedSquirrel
Hmm so would it be possible that keys And password authentication are used? If yes how do I go about disabling the password authentication and use just keys? (on the shared host)

well, it will try the authentications in a particular order. Usually, the password authentication fires off when the other ones have failed. ssh -vvv <hostname> should give you a detailed description of which methods are being tried and failing. So you wouldn't need to disable password auth, just make sure you're using another supported method and that it's set up right.

for example, if the permissions on the server side ~/.ssh directory aren't 0700 and the authorized_keys2 file isn't like 644, then keys will fail and it'll drop back to password.
 

QuixoticOne

Golden Member
Nov 4, 2005
1,855
0
0
Can't you use RSYNC to help with that?
Also, yeah, check to make sure that the RSA and DSA PKI login modes are BOTH really not possible to use since they would solve your problem.

Of course there are obvious scripting or modding ways to get SSH working for you (just recompile at worst).
But since it is a web site, alternatively, you could just have it archive itself into a snapshot and then download that over an authenticated SSL HTTPS session from the webserver itself assuming you have the right ability to use server side scripts/jobs/CGI/whatever with the right permissions to do what is needed.


 

Red Squirrel

No Lifer
May 24, 2003
68,457
12,611
126
www.anyf.ca
This is a shared server so I don't have access to do that kind of stuff. Also I am using rsync to transfer data from the mounted ssh folder to the backup destination.
 

Red Squirrel

No Lifer
May 24, 2003
68,457
12,611
126
www.anyf.ca
I sorta got keys to work, BUT now it asks for a passphrase... so I'm back to square one. Any way to automate entering the passphrase? I heard something about ssh-agent but its really not explained well. I have no idea where I'm suppose to enter the passphrase to so it knows it. It looks like I'd still be stuck entering it when the system reboots, not very practical at all.
 

QuixoticOne

Golden Member
Nov 4, 2005
1,855
0
0
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/...): newkey
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in newkey.
Your public key has been saved in newkey.pub.
The key fingerprint is:
5b:aa:.....
$ ls -al newkey*
-rw------- 1 1675 2008-08-17 16:26 newkey
-rw-r--r-- 1 399 2008-08-17 16:26 newkey.pub

Of course change slightly to generate a DSA key if desired.
 

Red Squirrel

No Lifer
May 24, 2003
68,457
12,611
126
www.anyf.ca
But isin't that a huge security issue? Anyone can run ssh-keygen, enter no key, and get on my server. I can restrict by using from="myhost" in the authorized_keys file but that does not seem to be working at all. I tried putting my hostname as well as my IP.
 

Red Squirrel

No Lifer
May 24, 2003
68,457
12,611
126
www.anyf.ca
Ok another problem, now that I created a key file, I cannot connect to any other ssh server from that server. Think its trying to use the key file for EVERY server now :/
 

Red Squirrel

No Lifer
May 24, 2003
68,457
12,611
126
www.anyf.ca
Decided to use expect instead, been playing with it and it does what I want. Will just be tedious as I need to create an expect script AND backup script for a single job but what I'm doing is writing a C++ program that will take an argument for a job profile and read the info from a text file then generate the required bash/expect scripts, execute them, then delete them. I could probably even go a step further and make it support a basic custom encryption for the password.

The public key stuff was making me nervous anyway, too much obscurity and possibility of a security issue due to something I don't know about.
 

yoda291

Diamond Member
Aug 11, 2001
5,079
0
0
- it isn't a security issue so long as you protect the private key file. Likely called id_dsa or newkey if you copied the above verbatim. anyone can run ssh-keygen, but keys work in pairs so as long as you don't disseminate the private key you generated yourself anywhere, you're ok.

- if it's trying the key for every server, take it out of .ssh and put it somewhere else with 700 permissions. When you connect, you specify which private key to use with the -i flag.

here's a question. Why do you need to do this automatically anyways? if you're using the sshfs stuff, pass the -o reconnect and it should re-establish the link due to failure itself. the only time you get an issue is if your client side reboots.
 

QuixoticOne

Golden Member
Nov 4, 2005
1,855
0
0
Yeah ssh-keygen uses in general the most random numbers your system can generate at the moment to generate a random unique keypair. It is not likely (in the crypto sense of astronomically improbable) that anyone else could find / discover that keypair. There has been one bug relating to Debian derived distributions where they used the wrong random number technique and the results weren't secure, but that was an isolated bug and has been fixed in updates for the affected systems for several months. Everyone else has been using ssh with RSA/DSA keys even without passphrases securely for ...years.

As yoda said, the secret key is secret, and is kept on the client (connecting) machine, and mustn't be disclosed. The public key can go on any server(s) you want to use that key to authenticate with and is possible to be public information without a serious compromise in security.

 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Exactly, if someone has your public key big deal, not much they can do with it. You generate your public/private key on your local machine, secure your private key, and distribute your public key to the servers/machines you need to connect to.
 

Red Squirrel

No Lifer
May 24, 2003
68,457
12,611
126
www.anyf.ca
Hmm good to know.

And I need to automate this as right now I do my backups manually, I rather do them automaticly. So even if system reboots I want it to work. It mounts the file system, does the rsync backup, then unmounts.

I've managed to get something working with "Exepect" though. Just writing a C++ program to make it easier to manage as I actually need 2 scripts per backup job and that would start to get messy. The C++ program generates it on the fly, runs it then deletes it after.
 

yoda291

Diamond Member
Aug 11, 2001
5,079
0
0
d00d, I think you want to go back to keys...and then do

rsync -var --rsh="ssh -i <private_key>" <src> username@remotehost:<dst>

that would be non-trivially more secure than what you have going on...and it fits on 1 line.
 

Red Squirrel

No Lifer
May 24, 2003
68,457
12,611
126
www.anyf.ca
Did not know I could specify the key in rsync. Will this still cause me troubles with places that don't use keys if I configure my client to use keys though? (that I want to manually connect to)
 

QuixoticOne

Golden Member
Nov 4, 2005
1,855
0
0
If the given -i identity file doesn't authenticate successfully in general by default it'll prompt for a password.
Also typically you'd fire off a destination specific rsync or ssh command line so you're using the appropriate PKI identity to authenticate to that particular host as well as using appropriate rsync or whatever options suited to that job. There's no major harm in using the same identity file for multiple remote hosts, though, as long as you keep the SECRET key secret locally. If you do use the same keypair for numerous hosts and your secret key is lost / compromised, though, well.....

 

Red Squirrel

No Lifer
May 24, 2003
68,457
12,611
126
www.anyf.ca
Yeah no luck, tried it with -i, I get the same thing as before "too many authentication failures". If I don't specify the -i then it asks for a password as normal. Only seems to work if I call the key id_rsa but then that only works on one server.
 

Red Squirrel

No Lifer
May 24, 2003
68,457
12,611
126
www.anyf.ca
Think I got it. Thanks for that rsync command btw... had no idea it had the capability of directly connecting to a server via ssh. I will modify my program to just use that, it will be more secure and less maintenance (no need to edit the password when I change it)
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |