Is there a way, to install an SSH key with a limited lifetime?

93 views Asked by At

I wrote a bash script to move some Apps (Redmine, Svn, Git, ..) from server A to server B.
At the beginning the script (running on A) installed an SSH key on B, so it could do ssh,scp etc. on server B, but asking me for a password only once.
Finally the script removes the SSH key from Server B like so:

ssh -i MyKey user@B "sed -i '/SPECIAL_TEXT_OF_MYKEY/d' ~/.ssh/authorized_keys"

OK - works for me (had to get around my 'cp -i' alias, but that is another story).
Here is my question:
Is it possible, to get a key removed or at least invalidated from authorized_keys automatically after some time period? Something like:

ssh-copy-id --invalidate-after=60min -i MY_TEMP_KEY user@B
1

There are 1 answers

1
Toni Schilling On

It is not my answer but it answers my question ..
Thanks to @dave_thompson_085 and @Bramer I found this:
https://superuser.com/questions/1598311/

So it looks like, removing the key by hand|script|cron|at
is a good and at this time the only solution.
May be I can use the Comment-Field to improve this a little bit.