1 |
Quoting Andrea Conti <alyf@××××.net>: |
2 |
|
3 |
> On 07/10/2010 18:45, Momesso Andrea wrote: |
4 |
> |
5 |
>> Setting up a public key, would do the job, but then, all the connections |
6 |
>> between the servers would be passwordless, so if server A gets |
7 |
>> compromised, also server B is screwed. |
8 |
> |
9 |
> Well, not really... public key authentication works on a per-user basis, |
10 |
> so all you get is that some user with a specific key can log in as some |
11 |
> other user of B without typing a password. |
12 |
> |
13 |
> Of course, if you authorize a given key for logging in as root@B, then |
14 |
> what you said is true. But that is a problem with the specific setup. |
15 |
> |
16 |
>> Is there a way to allow only one single command from a single cronjob to |
17 |
>> operate passwordless, while keeping all the other connections secured by |
18 |
>> a password? |
19 |
> |
20 |
> You can't do that on a per-command basis. You'd be trying to control the |
21 |
> authentication method accepted by sshd on B according to which command |
22 |
> is run on A -- something sshd on B knows nothing about. |
23 |
> |
24 |
> I would try the following way: |
25 |
> |
26 |
> - Set up an unprivileged user on B -- let's call it foo -- which can |
27 |
> only write to its own home directory, /home/foo. |
28 |
> |
29 |
> - add the public key you will be using (*) to foo@B's authorized_keys |
30 |
> file. You should set the key's options to |
31 |
> 'pattern="<address_of_A>",no-pty,command="/usr/bin/scp -t -- /home/foo"' |
32 |
> (man sshd for details). |
33 |
> |
34 |
> - chattr +i /home/foo/.ssh/authorized_keys, so that the file can only be |
35 |
> changed by a superuser (you can't just chown the file to root as sshd is |
36 |
> quite anal about the permissions of the authorized_keys file) |
37 |
> |
38 |
> Now your cron job on A can do "scp <file> foo@B:/home/foo" without the |
39 |
> need for entering a password; you just have to set up another cron job |
40 |
> on B that picks up the file from /home/foo and puts it where it should |
41 |
> go with the correct permissions, possibly after doing a sanity check on |
42 |
> its contents. |
43 |
> |
44 |
> If you use something else than scp, (e.g. rsync) you should also adjust |
45 |
> the command option in the key options above. |
46 |
> Note that the option refers to what is run on B, not on A. Also, it is |
47 |
> *not* an authorization directive à la /etc/sudoers (i.e., it does not |
48 |
> specify what commands the user is allowed to run): it simply overwrites |
49 |
> whichever command is requested by the client side of the ssh connection, |
50 |
> so that, for example, the client cannot request a shell or do "cat |
51 |
> <somefile>". |
52 |
> |
53 |
> (*) You can either use the key of the user running the cron job on A, or |
54 |
> generate a separate key which is only used for the copy operation. In |
55 |
> this case, you will need to tell scp the location of the private key |
56 |
> file with the -i option. |
57 |
> |
58 |
> HTH, |
59 |
> andrea |
60 |
> |
61 |
> |
62 |
|
63 |
Thank you all for your fast replies, I think I'll use all of your suggestions: |
64 |
|
65 |
-create an unprivilegied user with no shell access as Stroller and |
66 |
Andrea suggested |
67 |
|
68 |
-I'll setup a passwordless key for this user, only limited to a single |
69 |
command, as Willie |
70 |
suggested |
71 |
|
72 |
This sounds pretty sane to me. |
73 |
|
74 |
TopperH |
75 |
http://topperh.ath.cx |
76 |
|
77 |
---------------------------------------------------------------- |
78 |
This message was sent using IMP, the Internet Messaging Program. |