# Permission denied (publickey,gssapi-with-mic,password) close

## muhsinzubeir

Well I have a command that I am trying to get it running via a cron, but it works only if I trigger the bash script via the terminal.From the cron it just gives the error on the subject.This is the script:

```
#!/bin/bash

/usr/bin/rsync -e "/usr/bin/ssh -vvvi /admin/.ssh/id_dsa" -avzp --delete /local_dir remoteUser@xxxxxxxxx_ip:/remoted_dir
```

Log:

```

Permission denied (publickey,gssapi-with-mic,password).

rsync: connection unexpectedly closed (0 bytes received so far) [sender]

rsync error: unexplained error (code 255) at io.c(600) [sender=3.0.6]
```

Remote box shows this:

Failed password for admin from xxxss.xxxx.xxxx port 121212 ssh2

Failed password for admin from xxxxx.xxx.xxxx port 121212 ssh2

Running the same script manually via the terminal, all goes well.....anyone kind to help ? Thankx

P:S

**I have been googling and trying for a while with no luck ofcourse

----------

## tomk

Try adding -t to your ssh command, you may need to add it twice.

 *man ssh wrote:*   

>      -t      Force pseudo-tty allocation.  This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services.
> 
>              Multiple -t options force tty allocation, even if ssh has no local tty.
> 
> 

 

----------

## muhsinzubeir

Thanks for the quick response, trying that i get :

 *Quote:*   

> Pseudo-terminal will not be allocated because stdin is not a terminal.

 

This is a bit frustring error as it happens only when I put the script in the cron, which was the intention of the script ofcourse   :Smile: 

----------

## muhsinzubeir

Not so sure, but this script is suppose to ssh without password.But running via the cron, the remote box shows or expects password.Or atleast the ssh attempt to use password, and cli the script uses session stuffs with keys.Could it be that via cron, the env for the session not started or something ?

----------

## muhsinzubeir

Not so sure right now, but much likely that dsa and rsa was mixed up.

----------

## Hu

 *muhsinzubeir wrote:*   

> 
> 
> ```
> /usr/bin/rsync -e "/usr/bin/ssh -vvvi /admin/.ssh/id_dsa" -avzp --delete /local_dir remoteUser@xxxxxxxxx_ip:/remoted_dir
> ```
> ...

 Are these two usernames actually different in the logs or was this an editing mistake?

----------

## muhsinzubeir

 *Hu wrote:*   

>  *muhsinzubeir wrote:*   
> 
> ```
> /usr/bin/rsync -e "/usr/bin/ssh -vvvi /admin/.ssh/id_dsa" -avzp --delete /local_dir remoteUser@xxxxxxxxx_ip:/remoted_dir
> ```
> ...

 

Just editing mistake, much likely the mistake was using dsa and the remote box had authorized_keys instead of authorized_keys2.Will have to reverify that, as more boxes might use the same script.I will have to re-think later on as per security, may be rsync-server && rsync-clients will be much cleaner solution than this approach.

cheers

----------

