---
name: "ssh_auth"
section: "3"
platform: "linux"
package: "libssh-2-doc"
version: "0.2+svn20070321-4"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/ssh_auth"
---

# ssh\_auth(3)

functions to authenticate

## NAME

Ssh\_auth - functions to authenticate

### Functions

int **ssh\_userauth\_autopubkey** (SSH\_SESSION \*session)\
 *Tries to automaticaly authenticate with public key and 'none'.*  int **ssh\_userauth\_kbdint** (SSH\_SESSION \*session, char \*user, char \*submethods)\
 *Try to authenticate through the 'keyboard-interactive' method.*  char \* **ssh\_userauth\_kbdint\_getinstruction** (SSH\_SESSION \*session)\
 *get the 'instruction' of the message block*  char \* **ssh\_userauth\_kbdint\_getname** (SSH\_SESSION \*session)\
 *get the 'name' of the message block*  int **ssh\_userauth\_kbdint\_getnprompts** (SSH\_SESSION \*session)\
 *get the number of prompts (questions) the server has given*  char \* **ssh\_userauth\_kbdint\_getprompt** (SSH\_SESSION \*session, int i, char \*echo)\
 *get a prompt from a message block*  void **ssh\_userauth\_kbdint\_setanswer** (SSH\_SESSION \*session, unsigned int i, char \*answer)\
 *set the answer for a question from a message block.*  int **ssh\_userauth\_none** (SSH\_SESSION \*session, char \*username)\
 *Try to authenticate through the 'none' method.*  int **ssh\_userauth\_offer\_pubkey** (SSH\_SESSION \*session, char \*username, int type, STRING \*publickey)\
 *Try to authenticate through public key.*  int **ssh\_userauth\_password** (SSH\_SESSION \*session, char \*username, char \*password)\
 *Try to authenticate by password.*  int **ssh\_userauth\_pubkey** (SSH\_SESSION \*session, char \*username, STRING \*publickey, PRIVATE\_KEY \*privatekey)\
 *Try to authenticate through public key.*

## Detailed Description

functions to authenticate

## Function Documentation

### int ssh\_userauth\_autopubkey (SSH\_SESSION \* session)

Tries to automaticaly authenticate with public key and 'none'.

it may fail, for instance it doesn't ask for a password and uses a default asker for passphrases (in case the private key is encrypted)

**Parameters:**

*session* ssh session

**Returns:**

SSH\_AUTH\_ERROR : a serious error happened\
\
  SSH\_AUTH\_DENIED : Authentication failed : use another method\
\
  SSH\_AUTH\_PARTIAL : You've been partially authenticated, you still have to use another method\
\
  SSH\_AUTH\_SUCCESS : Authentication success

**See also:**

**ssh\_userauth\_kbdint()**

**ssh\_userauth\_password()**

**ssh\_options\_set\_identity()**

### int ssh\_userauth\_kbdint (SSH\_SESSION \* session, char \* user, char \* submethods)

Try to authenticate through the 'keyboard-interactive' method.

**Parameters:**

*session* ssh session \
 *user* username to authenticate. You can specify NULL if ssh\_option\_set\_username() has been used. You cannot try two different logins in a row. \
 *submethods* undocumented. Set it to NULL

**Returns:**

SSH\_AUTH\_ERROR : a serious error happened\
\
  SSH\_AUTH\_DENIED : Authentication failed : use another method\
\
  SSH\_AUTH\_PARTIAL : You've been partially authenticated, you still have to use another method\
\
  SSH\_AUTH\_SUCCESS : Authentication success\
\
  SSH\_AUTH\_INFO : The server asked some questions. Use **ssh\_userauth\_kbdint\_getnprompts()** and such.

**See also:**

**ssh\_userauth\_kbdint\_getnprompts()**

**ssh\_userauth\_kbdint\_getname()**

**ssh\_userauth\_kbdint\_getinstruction()**

**ssh\_userauth\_kbdint\_getprompt()**

**ssh\_userauth\_kbdint\_setanswer()**

### char\* ssh\_userauth\_kbdint\_getinstruction (SSH\_SESSION \* session)

get the 'instruction' of the message block

You have called **ssh\_userauth\_kbdint()** and got SSH\_AUTH\_INFO. this function returns the questions from the server

**Parameters:**

*session* ssh session

**Returns:**

instruction of the message block

### char\* ssh\_userauth\_kbdint\_getname (SSH\_SESSION \* session)

get the 'name' of the message block

You have called **ssh\_userauth\_kbdint()** and got SSH\_AUTH\_INFO. this function returns the questions from the server

**Parameters:**

*session* ssh session

**Returns:**

name of the message block. Do not free it

### int ssh\_userauth\_kbdint\_getnprompts (SSH\_SESSION \* session)

get the number of prompts (questions) the server has given

You have called **ssh\_userauth\_kbdint()** and got SSH\_AUTH\_INFO. this function returns the questions from the server

**Parameters:**

*session* ssh session

**Returns:**

number of prompts

### char\* ssh\_userauth\_kbdint\_getprompt (SSH\_SESSION \* session, int i, char \* echo)

get a prompt from a message block

You have called **ssh\_userauth\_kbdint()** and got SSH\_AUTH\_INFO. this function returns the questions from the server

**Parameters:**

*session* ssh session \
 *i* index number of the ith prompt \
 *echo* when different of NULL, it will obtain a boolean meaning that the resulting user input should be echoed or not (like passwords)

**Returns:**

pointer to the prompt. Do not free it

### void ssh\_userauth\_kbdint\_setanswer (SSH\_SESSION \* session, unsigned int i, char \* answer)

set the answer for a question from a message block.

You have called **ssh\_userauth\_kbdint()** and got SSH\_AUTH\_INFO. this function returns the questions from the server

**Parameters:**

*session* ssh session \
 *i* index number of the ith prompt \
 *answer* answer to give to server

### int ssh\_userauth\_none (SSH\_SESSION \* session, char \* username)

Try to authenticate through the 'none' method.

**Parameters:**

*session* ssh session \
 *username* username to authenticate. You can specify NULL if ssh\_option\_set\_username() has been used. You cannot try two different logins in a row.

**Returns:**

SSH\_AUTH\_ERROR : a serious error happened\
\
  SSH\_AUTH\_DENIED : Authentication failed : use another method\
\
  SSH\_AUTH\_PARTIAL : You've been partially authenticated, you still have to use another method\
\
  SSH\_AUTH\_SUCCESS : Authentication success

### int ssh\_userauth\_offer\_pubkey (SSH\_SESSION \* session, char \* username, int type, STRING \* publickey)

Try to authenticate through public key.

**Parameters:**

*session* ssh session \
 *username* username to authenticate. You can specify NULL if ssh\_option\_set\_username() has been used. You cannot try two different logins in a row. \
 *type* type of public key. This value is given by publickey\_from\_file() \
 *publickey* a public key returned by publickey\_from\_file()

**Returns:**

SSH\_AUTH\_ERROR : a serious error happened\
\
  SSH\_AUTH\_DENIED : The server doesn't accept that public key as an authentication token. Try another key or another method\
\
  SSH\_AUTH\_SUCCESS : The public key is accepted, you want now to use **ssh\_userauth\_pubkey()**

**See also:**

publickey\_from\_file()

privatekey\_from\_file()

**ssh\_userauth\_pubkey()**

### int ssh\_userauth\_password (SSH\_SESSION \* session, char \* username, char \* password)

Try to authenticate by password.

**Parameters:**

*session* ssh session \
 *username* username to authenticate. You can specify NULL if ssh\_option\_set\_username() has been used. You cannot try two different logins in a row. \
 *password* password to use. Take care to clean it after authentication

**Returns:**

SSH\_AUTH\_ERROR : a serious error happened\
\
  SSH\_AUTH\_DENIED : Authentication failed : use another method\
\
  SSH\_AUTH\_PARTIAL : You've been partially authenticated, you still have to use another method\
\
  SSH\_AUTH\_SUCCESS : Authentication success

**See also:**

**ssh\_userauth\_kbdint()**

### int ssh\_userauth\_pubkey (SSH\_SESSION \* session, char \* username, STRING \* publickey, PRIVATE\_KEY \* privatekey)

Try to authenticate through public key.

**Parameters:**

*session* ssh session \
 *username* username to authenticate. You can specify NULL if ssh\_option\_set\_username() has been used. You cannot try two different logins in a row. \
 *publickey* a public key returned by publickey\_from\_file() \
 *privatekey* a private key returned by privatekey\_from\_file()

**Returns:**

SSH\_AUTH\_ERROR : a serious error happened\
\
  SSH\_AUTH\_DENIED : Authentication failed : use another method\
\
  SSH\_AUTH\_PARTIAL : You've been partially authenticated, you still have to use another method\
\
  SSH\_AUTH\_SUCCESS : Authentication success

**See also:**

publickey\_from\_file()

privatekey\_from\_file()

private\_key\_free()

**ssh\_userauth\_offer\_pubkey()**
