set home "/home/username" #### su - gpg --import ./.pgp/pubring.pkr (gpg asks if I'm sure (y/n), I say, "y") (gpg then asks for a passphrase and I enter it). then ~/.gnupg is created by gpg for #### my $exp = new Expect; $exp->spawn("sudo -u $user gpg --import $home/.pgp/secring.skr"); $exp->send("set home $home\n"); #THS DOESN'T WORK...just an example of something i tried $exp->expect(5, [qr'\(y/N\)\s*' , sub {my $exph = shift; print $exph "y\r" ;exp_continue; }], [qr'passphrase:\s*' , sub {my $exph = shift; print $exph "$passphrase";exp_continue; }], [EOF => sub {die "Error: Could not login!\n"; }], [timeout => sub {die "Error: Could not login!\n"; }], '-re', '\$');