Mac os X - ssh command

I am trying to build a little applications and want to be able to use the unix shell to run ssh
so i can run the ssh command and read and write to the connection.
I tried to use the Runtime with the exec command but i get an error saying ssh is unknown command, but i can use commands like "ls" and get the output
any ideas?
cheers

If you're at a terminal window and you can type ssh and it works, then ssh is in your PATH. However, the environment you get when you use Runtime.exec is not the same as in a terminal window. It won't have run all the .zshrc, etc. files that you get with the terminal, so the PATH is different.
You'll need to either specify the full path, like runtime.exec("/usr/bin/sss blah") or else exec a shell script that sources the proper .zshrc or whatever files.
Note, however, that you still might have problems. ssh might be one of those programs that only accepts input from a terminal, not from arbitrary pipes or streams.

Similar Messages

  • How can i install snow leopard on my mac G5 using a command line and booting from an external usb rom, since my disk i have is not a bootable media

    How can i install snow leopard on my mac G5 using a command line and booting from an external usb rom, since my disk i have is not a bootable media

    Hi.
    You simply can't. Snow Leopard is compiled in Intel binary only.
    Good Luck.

  • Running ssh command from java and then answering password prompt

    Hi,
    I have a situation that has not solved yet. I am running ssh command from unix terminal without any problem, and then i enter password.
    For example :
    [oracle@fuata]:/export/home/oracle> ssh -N [email protected] -L 9901:127.0.0.1:9999
    Password:
    It is working. I have question that how can i perform this in java? I am thinking that i can run ssh command by using Runtime Class, it is ok. But how can i answer the password? I am a bit confused. Is there any example looks like this?
    Thanks for responses.

    futi wrote:
    Thanx. Firstly i insisted to do this without jsch but actually this is harder than jsch. I edit some of code pieces PortForwardingL.java and could run it. It works problem-free. Could you say why you "insisted" on this approach. It can't be for speed+ since jsch is very fast. It can't be for portability+ since jsch is portable but the use of Runtime.exec() requires the installation of ssh software. It can't be because of limitations+ since jsch is a fully featured library. It can't be for security+ since jsch is secure. It can't be for ease of use+ since jsch is much easier to use than ssh with Runtime.exec(). Unless it's a licensing issue, it can't be for commercial+ reasons since jsch is free. The only reason I can think of why one would "insisted" on this approach is if it is for some college project.

  • Running ssh command in a java application

    Hi there!
    I am trying to run a ssh command from a java application cause I need to store the result.
    Actually I can run this command in the cygwin shell so I need to open the shell and run the command, all trough java.
    so, what my process needs to do is:
    1) open the cmd
    2) run C:\cygwin\cygwin.bat
    3) execute the ssh command
    ssh -l fip-user ipdb fip 42704) print the result of the ssh command.
    Note that the cygwin opens in the same command line window and so will print it's result to the same process inputstream
    Message was edited by:
    RBervini

    Use "Runtime.getRuntime().exec()" to execute the SSH program,
    and you can then get the output of the SSH program
    via the getInputStream() method on the returned Process object.
    Note: there are many pitfalls with this. In particular, most people don't know
    they should create separate threads to drain the input/output pipes.
    See this excellent classic article http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    on how to do it right.

  • Error while transferring file :: Error while issuing ssh command.

    Hi All,
    I am having a JSP based website application.
    I am getting the following exception in my logs.
    [ERROR] 05/04/2007 03:43:44 - Error while transferring file :: Error while issuing ssh command.
    java.net.ConnectException: Connection timed out
                at java.net.PlainSocketImpl.socketConnect(Native Method)
                at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
                at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
                at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
                at java.net.Socket.connect(Socket.java:464)
                at java.net.Socket.connect(Socket.java:414)
                at java.net.Socket.<init>(Socket.java:310)
                at java.net.Socket.<init>(Socket.java:125)
                at com.sshtools.j2ssh.net.SocketTransportProvider.<init>(Unknown Source)
                at com.sshtools.j2ssh.net.TransportProviderFactory.connectTransportProvider(Unknown Source)
                at com.sshtools.j2ssh.SshClient.connect(Unknown Source)
                at com.sshtools.j2ssh.SshClient.connect(Unknown Source)
                at com.sshtools.j2ssh.SshClient.connect(Unknown Source)
                at com.novartis.util.DataExporter.transportFile(DataExporter.java:127)
                at com.novartis.util.DataExporter.export(DataExporter.java:101)
                at com.novartis.businessmanagers.SandosSignupManagerPojoImpl.export(SandosSignupManagerPojoImpl.java:103)
                at com.novartis.util.DataExportJob.process(DataExportJob.java:48)
                at com.novartis.util.ExclusiveJob.execute(ExclusiveJob.java:35)
                at org.quartz.core.JobRunShell.run(JobRunShell.java:191)
                at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:516)Any help would be appreciated.
    Thanks.

    This means that the SSH server you're trying to connect to isn't listening. Is the SSH server running? Are you trying to connect to the right machine?

  • Giving Password to a ssh command in a script

    Hi
      I wanna know how to give password to a ssh command in a script... that is my command iniside script is
    q=`ssh 172.16.1.2 /usr/sbin/alternatives --config java </root/Desktop/2.txt 2>&1 | grep jdk1.6.0_05`
    when i execute the script file and when this commands get executed it prompts for passord.. i dont want the script to wait for password from the terminal
    i have also obtained the password as follows
    #! /bin/sh
    read ip
    echo $ip
    oldmodes=`stty -g`
    stty -echo
    read password
    stty $oldmodes
    i want to give this password which i obtained to the command so that it doesnt wait for a password at a terminal

    I suggest you use ssh-keys without a password for this purpose:
    http://www.linuxhelp.net/guides/ssh/
    --> no need for a password.
    Markus

  • Run ssh command in labview

    does anyone knows how to run an ssh command in labview?
    I know how to run some linux commands in labview but my problem is when I try to run an ssh command ...
    thks
    JP

    Unfortunetly, I don't know how to script in a password for ssh. SSH closes the stdin and re-opens the tty that you are logged in at. This is actually a security feature. As well as a way to send stdin to remote programs (otherwise your password would get in the way.)
    If you don't need to ssh to a remote host, and you want to chmod something on the localhost, you could use sudo instead. With sudo you can specify certain users (or all users) to run certain commands. (so you could make a shell script to chmod for you).
    I don't know your exact needs, but I think that a public/private keypair could still work. In your authorized keys file on your "root" account, you can even specify that "this public key does not get shell access, and can only execu
    te this one command." This would probably be the most secure method. But it requires the user to have the correct private key as well.
    If you know that won't work for some reason, then maybe you could setup a inetd process that will execute a command whenever someone connects to a certain port (then you could use LabVIEW's TCP VIs).
    Or, if you are not connecting remotely, you could setuid your LabVIEW executable (A VERY BAD IDEA!).
    Also, it is possible to script "telnet." It would of course transmit your root password as plaintext, but trying to script your ssh session would also embed your password in your LabVIEW VI. Out internet toolkit for LabVIEW has some helpful telnet VIs.
    May I ask why you want to chmod something on a remote system that requires root? Sounds like maybe you should create a LabVIEW application on the remote side that acts as a daemon (running as root) and accepts connections and commands and does the chmodding for you.
    -Duffey

  • What is the Mac equivalent of the command "ctrl shift  I"  for a PC

    HI
    what is the Mac equivalent of the command "ctrl+shift + I"  for a PC to get to the cookies and delete them

    It varies depending on which browser you're using. In Safari, choose Preferences from the Safari menu, click on the Privacy tab, and then on Details.
    (101212)

  • Total nube to jws, need to run ssh command via web or jws?

    Ok So we had a developer that created this application that can basically run ssh commands via jws I believe. Unfortunately he is no longer here. I am wondering how you do this? I know tha commands that are already set up, but I have no idea how to implement it into my project.
    I am using Struts 2, Java 5, Weblogic 9.2, Spring
    Thanks
    orozcom

    Have a look at:
    http://www.jcraft.com/jsch/
    basically you'd need a small webstart client to wrap something like the above library. Best thing is to try with a standalone java client first. Once that is working have a look at turning it into a webstart app.

  • Remote ssh commands with wild cards

    I am trying to send a remote command via ssh - need to get a file listing in a directory using a wild card. However, the ssh command will not return results using a wild card:
    ssh [email protected] sudo ls -l /var/audit-files/201110* (directory requires root permission)
    /var/audit-files/201110*: No such file or directory
    I've tried quoting the command, the directory, the file names, etc - same results. It will only work with a specific name that exists, but not with a wild card. Is there a way to make this work?

    This is a rather complex situation. The problem is that you need to quote the '*' character; however, quoting it once may not be enough. Every time the command goes through a shell you'll strip out a set of quotes. It isn't clear to me how many times this will go through the shell but I'm guessing you'll have to at least double quote it.
    ssh [email protected] sudo ls -l "/var/audit-files/201110\*"
    I won't guarantee that this will work but it might. I don't know what the permissions are on /var/audit_files. If you need root to read that you may need to triple quote it. I've never had much luck getting the quotes right in complicated situations like this.

  • Cannot start NodeManager Remotly (Via SSH Commands)

    Hi all,
    we are going to start the node manager of one of the cluster servers via SSH command.
    But it is not starting. We can start it directly by log in to that server and run startNodemanager.sh script.
    What is the issue?
    Thanks,
    Nir

    Hi are you able to start Node manager using following WLST Command :
    startNodeManager(verbos='true',NodeManagerHome='$WL_HOME/common/nodemanager',ListenPort='<PortNo>',ListenAddress='<HostName')
    And also can check NodeManager Log files for errors .
    Regards
    Edited by: TheKop88 on Jun 5, 2013 6:13 PM

  • Ssh command execution

    Is there a way to execute commands on a cisco device by giving only one ssh command from a computer?

    Hi Matthew,
    I understand what you are saying - To be honest with you, I do not know if an SSH single line entry is there to automate such a process you are requesting...
    But there is an option in IOS called as "Embedded Event Manager" (EEM) -
    Please take a look at it. See if this is something that would help you out.
    http://www.cisco.com/en/US/products/sw/iosswrel/ps5207/products_command_reference_chapter09186a00801a8085.html
    Cheers
    Gilbert
    Note: I had never used it before but playing around with it might help or atleast give you an idea. Sorry for not giving you a direct answer.

  • What is the best way to call SSH commands through Java technologies

    What is the best way to call SSH commands through Java technologies

    I don't think you can specify the password at the prompt using ssh. Plink has the -pw command option for passwords. What I did was except ssh to ask me and write the password programmatically through the outputStream I obtained from my Process object. I looked for "password: ", and then wrote the password with a trailing newline.
    Both plink and ssh will also ask if you trust the host if it is the first time you are connecting to it. So before just writing the password, check if the program wants verification from you: normally supplying "y" or "n". This should only have to happen the first time the client connects. It looks like thisPLINK:
    The server's host key is not cached in the registry. You
    have no guarantee that the server is the computer you
    think it is.
    The server's key fingerprint is:
    1024 f8:43:61:4c:a2:5b:77:be:5b:a7:bb:1f:f7:79:b3:b7
    If you trust this host, enter "y" to add the key to
    PuTTY's cache and carry on connecting.
    If you want to carry on connecting just once, without
    adding the key to the cache, enter "n".
    If you do not trust this host, press Return to abandon the
    connection.
    Store key in cache? (y/n)
    SSH:
    The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
    RSA key fingerprint is e1:02:13:c8:52:c2:23:41:9b:5b:58:2c:18:e6:59:af.
    Are you sure you want to continue connecting (yes/no)?What I did was read character by character from the inputStream until I found things of interest ... like "password: ". You only need to search for this in your method which will launch the ssh or plink Process. Once you have verifyed yourself, you can just pass commands to the Process, which is an ssh connection.
    My suggestion is to read() each byte from the Process's inputStream and write it to stdout. Look and see what you need to be looking for so you can interactive with the program correctly. You can't use readLine here becuase when the ssh asks for the password it does not print a newline. I do know for sure, that ssh will simply print, "passowrd: ". Plink will print this as well if the -pw option is not supplied.

  • How to execute multiple SSH commands using Ganymed

    I try to use Ganymed SSH to send and receive commands to/from the SSH server.
    However Ganymed example shows only sending one single SSH command to the SSH server.
    Does anybody know how to send and receive multiple commands to/from SSH server?

    I tried many times and it did not work. Please help.
    The output is this :
    Last login: Tue Oct  6 23:05:10 2009 from 192.168.1.4
    /bin/ls -aldf -k[root@linux ~]# /bin/ls -aldf -kExit status : nullI enclose the
    import ch.ethz.ssh2.ChannelCondition;
    import ch.ethz.ssh2.Connection;
    import ch.ethz.ssh2.KnownHosts;
    import ch.ethz.ssh2.Session;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.OutputStreamWriter;
    public class TestClient01 implements Runnable {
        static final String knownHostPath = "~/.ssh/known_hosts";
        static final String idDSAPath = "~/.ssh/id_dsa";
        static final String idRSAPath = "~/.ssh/id_rsa";
        private String host = "192.168.1.2";
        private String username = "root";
        private String password = "1234567";
        private KnownHosts database = new KnownHosts();
        private OutputStreamWriter writer = null;
        private Connection conn = null;
        private Session sess = null;
        public void writeCommand(String s) {
            try {
                writer.write(s);
                writer.flush();
            } catch(Exception ex) {}
        public void close() {
            if (writer==null) return;
            try {
                writer.close();
                sess.close();
                conn.close();
            } catch(Exception ex) {}
            if (writer!=null) writer = null;
        public void run() {
            try {
                conn = new Connection(host);
                conn.connect();
                boolean isAuthenticated = conn.authenticateWithPassword(username, password);
                if (!isAuthenticated) throw new IOException("Authentication failed.");
                sess = conn.openSession();
                new Thread(new SyncPipe(sess.getStderr(), System.err)).start();
                new Thread(new SyncPipe(sess.getStdout(), System.out)).start();
                sess.requestPTY("bash");
                sess.startShell();
                writer = new OutputStreamWriter(sess.getStdin(), "utf-8");
                writeCommand("/bin/ls -al");
                writeCommand("df -k");
                sess.waitForCondition(ChannelCondition.CLOSED | ChannelCondition.EOF |
                        ChannelCondition.EXIT_STATUS, 10000);
                System.out.println("Exit status : " + sess.getExitStatus());
            } catch (Exception e) {
                e.printStackTrace(System.err);
                System.exit(2);
        public static void main(String[] args) throws Exception { new TestClient01().run();}
        class SyncPipe implements Runnable {
            String CVS_VERSION = "$Revision: 1.1 $ $Id: SyncPipe.java,v 1.1 2008-09-30 03:47:56 sabre Exp $ ";
            private final byte[] buffer_;
            private final OutputStream ostrm_;
            private final InputStream istrm_;
            private boolean closeAfterCopy_ = false;
            public SyncPipe(InputStream istrm, OutputStream ostrm) { this(istrm, ostrm, 4096);}
            public SyncPipe(InputStream istrm, OutputStream ostrm, int bufferSize) {
                if (istrm == null) throw new IllegalArgumentException("'istrm' cannot be null");
                if (ostrm == null) throw new IllegalArgumentException("'ostrm' cannot be null");
                if (bufferSize < 1024) throw new IllegalArgumentException("a buffer size less than 1024 makes little sense");
                istrm_ = istrm;
                ostrm_ = ostrm;
                buffer_ = new byte[bufferSize];
            public void handleException(IOException e) { e.printStackTrace();}
            public SyncPipe setCloseAfterCopy(boolean closeAfterCopy) {
                closeAfterCopy_ = closeAfterCopy;
                return this;
            public void run() {
                try {
                    for (int bytesRead = 0; (bytesRead = istrm_.read(buffer_)) != -1;)
                        ostrm_.write(buffer_, 0, bytesRead);
                    ostrm_.flush();
                    if (closeAfterCopy_) ostrm_.close();
                } catch (IOException e) { handleException(e);}
    }

  • Apple Remote Desktop - sending SSH commands to linux clients

    Has anyone been able to configure ARD to send SSH commands to linux clients?
    The VNC part works, but not sure how to configure the UNIX commands.
    We are trying to be able to send rpm, df, etc commands to multiple centos clients at one time...
    thanks.

    not sure how to configure the UNIX commands.
    You can't. That's not a feature of ARD.

Maybe you are looking for