Rundeck by default uses SSH to execute commands on remote nodes, SCP to copy scripts to remote nodes, and locally executes commands and scripts for the local (server) node.
The SSH plugin expects each node definition to have the following properties in order to create the SSH connection:
hostname
: the hostname of the remote node. It can be in the format "hostname:port" to indicate that a non-default port should be used. The default port is 22.username
: the username to connect to the remote node.When a Script is executed on a remote node, it is copied over via SCP first, and then executed. In addition to the SSH connection properties above, these node attributes can be configured for SCP:
file-copy-destination-dir
: The directory on the remote node to copy the script file to before executing it. The default value is C:/WINDOWS/TEMP/
on Windows nodes, and /tmp
for other nodes.osFamily
: specify "windows" for windows nodes.In addition, for both SSH and SCP, you must either configure a public/private keypair for the remote node or configure the node for SSH Password authentication.
Out of the box typical node configuration to make use of these is simple.
hostname
attribute for the nodes. It can be in the format "hostname:port" to indicate that a non-default port should be used. The default port is 22.username
attribute for the nodes to the username to connect to the remote node.This will allow remote command and script execution on the nodes.
See below for more configuration options.
Sudo Password Authentication
The SSH plugin also includes support for a secondary Sudo Password Authentication. This simulates a user writing a password to the terminal into a password prompt when invoking a "sudo" command that requires password authentication.
In addition to the general SSH configuration mentioned for in this section, some additional configuration can be done for SCP.
When a Script is executed on a remote node, it is copied over via SCP first, and then executed. In addition to the SSH connection properties, these node attributes can be configured for SCP:
file-copy-destination-dir
: The directory on the remote node to copy the script file to before executing it. The default value is C:/WINDOWS/TEMP/
on Windows nodes, and /tmp
for other nodes.osFamily
: specify "windows" for windows nodes.SSH authentication can be done in two ways, via password or public/private key.
By default, public/private key is used, but this can be changed on a node, project, or framework scope.
The mechanism used is determined by the ssh-authentication
property. This property can have two different values:
password
privateKey
(default)When connecting to a particular Node, this sequence is used to determine the correct authentication mechanism:
ssh-authentication
attribute on the Node. Applies only to the target node.project.ssh-authentication
property in project.properties
. Applies to any project node by default.framework.ssh-authentication
property in framework.properties
. Applies to all projects by default.If none of those values are set, then the default public/private key authentication is used.
The username used to connect via SSH is taken from the username
Node attribute:
username="user1"
This value can also include a property reference if you want to dynamically change it, for example to the name of the current Rundeck user, or the username submitted as a Job Option value:
${job.username}
- uses the username of the user executing the Rundeck execution.${option.someUsername}
- uses the value of a job option named "someUsername".If the username
node attribute is not set, then the static value provided via project or framework configuration is used. The username for a node is determined by looking for a value in this order:
username
node attribute. Can contain property references to dynamically set it from Option or Execution values.project.ssh.user
property in project.properties
file for the project.framework.ssh.user
property in framework.properties
file for the Rundeck installation.The default authentication mechanism is public/private key.
The built-in SSH connector allows the private key to be specified in several different ways. You can configure it per-node, per-project, or per-Rundeck instance.
When connecting to the remote node, Rundeck will look for a property/attribute specifying the location of the private key file, in this order, with the first match having precedence:
ssh-keypath
attribute on the Node. Applies only to the target node.project.ssh-keypath
property in project.properties
. Applies to any project node by default.framework.ssh-keypath
property in framework.properties
. Applies to all projects by default.If you private key is encrypted with a passphrase, then you can use a "Secure Option" to prompt the user to enter the passphrase when executing on the Node. See below.
Using a passphrase for privateKey authentication works in the following way:
Therefore Private Key Passphrase authentication has several requirements and some limitations:
Passphrases are input either via the GUI or arguments to the job if executed via CLI or API.
To enable SSH Private Key authentication, first make sure the ssh-authentication
value is set (#authentication-types. Second, configure the path to the private key file (#ssh-private-keys).
Next, configure a Job, and include an Option definition where secureInput
is set to true
. The name of this option can be anything you want, but the default value of sshKeyPassphrase
assumed by the node configuration is easiest.
If the value is not sshKeyPassphrase
, then make sure to set the following attribute on each Node for password authentication:
ssh-key-passphrase-option
= "option.NAME
" where NAME is the name of the Job's secure option.An example Node and Job option configuration are below:
1 |
|
Job:
1 |
|
Password authentication works in the following way:
Therefore Password authentication has several requirements and some limitations:
Passwords for the nodes are input either via the GUI or arguments to the job if executed via CLI or API.
To enable SSH Password authentication, first make sure the ssh-authentication
value is set as described in Authentication types.
Next, configure a Job, and include an Option definition where secureInput
is set to true
. The name of this option can be anything you want, but the default value of sshPassword
assumed by the node configuration is easiest.
If the value is not sshPassword
, then make sure to set the following attribute on each Node for password authentication:
ssh-password-option
= "option.NAME
" where NAME is the name of the Job's secure option.An example Node and Job option configuration are below:
1 |
|
Job:
1 |
|
The SSH provider supports a secondary authentication mechanism: Sudo password authentication. This is useful if your security requirements are such that you require the SSH connection to be under a specific user's account instead of a generic "rundeck" account, and you still need to allow "sudo" level commands to be executed requiring a password to be entered.
This works in the following way:
Similarly to SSH Password authentication, Sudo Password Authentication requires:
Therefore Sudo Password Authentication has several requirements and some limitations:
Passwords for the nodes are input either via the GUI or arguments to the job if executed via CLI or API.
To enable Sudo Password Authentication, set the sudo-command-enabled
property/attribute to true
.
You can configure the way the Sudo Password Authentication works by setting these properties at the Node, Project or Rundeck scopes. Simply set the attribute name on a Node, the project.NAME
in project.properties, or framework.NAME
in framework.properties:
sudo-command-enabled
- set to "true" to enable Sudo Password Authentication.sudo-command-pattern
- a regular expression to detect when a command execution should expect to require Sudo authentication. Default pattern is ^sudo$
.sudo-password-option
- an option reference ("option.NAME") to define which secure option value to use as password. The default is option.sudoPassword
.sudo-prompt-pattern
- a regular expression to detect the password prompt for the Sudo authentication. The default pattern is ^\[sudo\] password for .+: .*
sudo-failure-pattern
- a regular expression to detect the password failure response. The default pattern is ^.*try again.*
.sudo-prompt-max-lines
- maximum lines to read when expecting the password prompt. (default: 12
).sudo-prompt-max-timeout
- maximum milliseconds to wait for input when expecting the password prompt. (default 5000
)sudo-response-max-lines
- maximum lines to read when looking for failure response. (default: 2
).sudo-response-max-timeout
- maximum milliseconds to wait for response when detecting the failure response. (default 5000
)sudo-fail-on-prompt-max-lines
- true/false. If true, fail execution if max lines are reached looking for password prompt. (default: false
)sudo-success-on-prompt-threshold
- true/false. If true, succeed (without writing password), if the input max lines are reached without detecting password prompt. (default: true
).sudo-fail-on-prompt-timeout
- true/false. If true, fail execution if timeout reached looking for password prompt. (default: true
)sudo-fail-on-response-timeout
- true/false. If true, fail on timeout looking for failure message. (default: false
)Note: the default values have been set for the unix "sudo" command, but can be overridden if you need to customize the interaction.
Next, configure a Job, and include an Option definition where secureInput
is set to true
. The name of this option can be anything you want, but the default value of sudoPassword
recognized by the plugin can be used.
If the value is not sudoPassword
, then make sure to set the following attribute on each Node for password authentication:
sudo-password-option
= "option.NAME
" where NAME is the name of the Job's secure option.An example Node and Job option configuration are below:
1 |
|
Job:
1 |
|
You can enable a further level of sudo password support for a node. If you have the requirement of executing a chain of "sudo" commands, such as "sudo -u user1 sudo -u user2 command", and need to enable password input for both levels of sudo. This is possible by configuring a secondary set of properties for your node/project/framework.
The configuration properties are the same as those for the first-level of sudo password authentication described in Configuring Secondary Sudo Password Authentication, but with a prefix of "sudo2-" instead of "sudo-", such as:
sudo2-command-enabled="true"
sudo2-command-pattern="^sudo .+? sudo .*$"
This would turn on a mechanism to expect and respond to another sudo password prompt when the command matches the given pattern.
If a value for "sudo2-password-option" is not set, then a default value of option.sudo2Password
will be used.
A note about the "sudo2-command-pattern":
The sudo authentication mechanism uses two regular expressions to test whether it should be invoked.
For the first sudo authentication, the "sudo-command-pattern" value is matched against the first component of the command being executed. The default value for this pattern is ^sudo$
. So a command like "sudo -u user1 some command" will match correctly. You can modify the regular expression (e.g. to support "su"), but it will always only match against the first part of the command.
If "sudo2-command-enabled" is "true", then the "sudo2-command-pattern" is also checked and if it matches then another sudo authentication is enabled. However this regular expression is tested against the entire command string to make it possible to determine whether it should be enabled. The default value is ^sudo .+? sudo .*$
. If necessary you should customize the value.
Here's an example of SSH RSA key generation on a Linux system:
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/demo/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/demo/.ssh/id_rsa.
Your public key has been saved in /home/demo/.ssh/id_rsa.pub.
The key fingerprint is:
a7:31:01:ca:f0:62:42:9d:ab:c8:b7:9c:d1:80:76:c6 demo@ubuntu
The key's randomart image is:
+--[ RSA 2048]----+
| .o . . |
|. * . . |
|. = = . |
| = E . |
|+ + o S . |
|.o o . = |
| o + . |
| + |
| |
+-----------------+
To be able to directly ssh to remote machines, the SSH public key of the client should be shared to the remote machine.
Follow the steps given below to enable ssh to remote machines.
The ssh public key should be copied to the authorized_keys
file of the remote machine. The public key will be available in ~/.ssh/id_rsa.pub
file.
The authorized_keys
file should be created in the .ssh
directory of the remote machine.
The file permission of the authorized key should be read/write for the user and nothing for group and others. To do this check the permission and change it as shown below.
$ cd ~/.ssh
$ ls -la
-rw-r--r-- 1 raj staff 0 Nov 22 18:14 authorized_keys
$ chmod 600 authorized_keys
$ ls -la
-rw------- 1 raj staff 0 Nov 22 18:14 authorized_keys
The permission for the .ssh directory of the remote machine should be read/write/execute for the user and nothing for the group and others. To do this, check the permission and change it as shown below.
$ ls -la
drwxr-xr-x 2 raj staff 68 Nov 22 18:19 .ssh
$ chmod 700 .ssh
$ ls -la
drwx------ 2 raj staff 68 Nov 22 18:19 .ssh
If you are running Rundeck on Windows, we heartily recommend using Cygwin on Windows as it includes SSH and a number of Unix-like tools that are useful when you work in a command line environment.
To pass environment variables through remote command dispatches, it is required to properly configure the SSH server on the remote end. See the AcceptEnv
directive in the "sshd_config(5)" manual page for instructions.
Use a wild card pattern to permit RD_
prefixed variables to provide open access to Rundeck generated environment variables.
Example in sshd_config:
# pass Rundeck variables
AcceptEnv RD_*