Modify jenkins sshd server to run interactive bash shell

Step 1: Modify jenkins sshd server

This will additionally run a bash shell
Turn on jenkins sshd server and set port.

// Activate sshd server
// "Manage Jenkins"
//    ->
//    "Configure Global Security"
// then copy/paste this into script console

import jenkins.model.*;
import org.apache.sshd.server.shell.*;

def inst = Jenkins.getInstance()
def sshDesc = inst.getDescriptor(
    "org.jenkinsci.main.modules.sshd.SSHD")

sshDesc.sshd.setShellFactory(
    InteractiveProcessShellFactory.INSTANCE)
println 'Done with step 1!'

Step 2: get sh shell

ssh -p <jenkins-sshd-port> <jenkins-fqdn>

Step 3: get python shell

python -i

Step 4: spawn pty bash shell

>>> import pty
>>> pty.spawn("/bin/bash")

NOTE: bash shell has a weird double echo effect

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s