Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

To give a background on the problem,we have multiple unix boxes in our office. And they have instances of weblogic running on them. Also, we have only SSH access to the unix boxes.
So, the question is there a way to programmatically execute the unix commands, without being logging on to the unix servers manually? I am aware of jsch which is used for java ssh connections. I am just looking for a better way of doing it.

sshd_config Details
These include only the difference.Rest as same as sehe's mentioned in the comments.

    AllowTcpForwarding no
Banner /etc/issue
Ciphers aes128-ctr,aes128-cbc,arcfour,3des-cbc,blowfish-cbc
ClientAliveCountMax 0
ClientAliveInterval 900
HostBasedAuthentication no
HostKey /etc/ssh/ss_hhost_rsa_key
LoginGraceTime 120
MaxAuthTries    3
PrintMotd yes
PubkeyAuthentication yes
RSAAuthentication yes
Subsystem       sftp    /usr/lib/ssh/sftp-server
share|improve this question

migrated from stackoverflow.com Apr 23 '11 at 10:49

This question came from our site for professional and enthusiast programmers.

1  
Am I the only one detecting the contradiction between 'We are not the one controlling UNIX boxes' and 'Programmatically Restart servers using SSH'? –  sehe Apr 23 '11 at 10:23
    
I know it sounds contradictory[probably I need to phrase it better in future] but we have rights only to application deployment and not to the root of the unix machines. –  Balajee Apr 23 '11 at 10:29
add comment

3 Answers 3

up vote 0 down vote accepted

ssh keygen should not be hard at all

If you have logon rights, then normally you have all the permissions required

Use PuttyGen.exe on the windows side (if it's windows), otherwise ssh-keygen will do


Append the public key (in ssh format) to authorized_keys (in your home folder, so you have permissions).

The only reason why this wouldn't work is

  • with (bad) old versions of sshd
  • when sshd_config explicitely prohibits public key auth - in which case... Well you have to talk to the admins (communication is always harder than technological tricks :))

Info

On my OpenSolaris server I have the following sshd_config

sehe@osol147:/etc/ssh$ grep -v ^# sshd_config  | sort -u

GatewayPorts no
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_rsa_key
IgnoreRhosts yes
KeepAlive yes
KeyRegenerationInterval 3600
ListenAddress ::
LoginGraceTime 600
LogLevel info
MaxAuthTries    6
MaxAuthTriesLog 3
PAMAuthenticationViaKBDInt yes
PasswordAuthentication yes
PermitEmptyPasswords no
PermitRootLogin yes
Port 22
PrintMotd no
Protocol 2
RhostsAuthentication no
RhostsRSAAuthentication no
RSAAuthentication yes
ServerKeyBits 768
StrictModes yes
Subsystem       sftp    internal-sftp
SyslogFacility auth
X11DisplayOffset 10
X11Forwarding yes
X11UseLocalhost yes
share|improve this answer
    
The server is Solaris 5.10. And I generated the public and private key and attempted using putty.exe but the server refused the key.Is it that the passphrase of the private key should be same as your password.Tutorial link I referred.- linux-sxs.org/networking/openssh.putty.html –  Kunal Jha Apr 23 '11 at 10:55
    
Mmm. no passphrases won't have any influence server-side. You might have forgotten to chmod go-rwx your key files (I also -w the privkey myself); the same goes server side for the authorized_keys file. You could inspect /etc/ssh/sshd_config (or thereabouts) to see whether the server is prohibiting pubkey authentication. –  sehe Apr 23 '11 at 11:13
    
attached a snippet of my own sshd_config –  sehe Apr 23 '11 at 11:18
add comment

Use key authentication to be able to ssh without password. Look at ssh-keygen to generate a key on the client, and ssh-copy-id server to copy it to the server. ssh server should then work passwordless.

It is then a simple matter to run ssh server command programatically.

share|improve this answer
    
Thanks but we are not the ones controlling unix boxes. And we are in corporate environment, so the ssh-keygen solution will be hard to implement for big team( 15 people). –  Balajee Apr 23 '11 at 9:07
    
Well, you asked the question and then go on to discredit the correct anwer... Hmmm. problem solved? –  sehe Apr 23 '11 at 10:17
1  
note that ssh-copy-id does something like cat ~/.ssh/id_rsa.pub | ssh server 'cat >> .ssh/authorized_keys' (in case you don't have the command) –  sehe Apr 23 '11 at 10:24
add comment

Check this out. It has lot of ways to use python for ssh.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.