Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By masijade

Thread: Need code Snippet to switch users in unix

  1. #1
    mohtashims is offline Member
    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Exclamation Need code Snippet to switch users in unix

    Hi,

    Can anyone share the standalone java code to connect to unix server and switch unix users using unix "ssh" command.

    I have already exchanged ssh keys between user1 and user2 on unix server1.

    Thus, i wish to connect to unix server1 with user1 / password.

    After logging in successfully I wish to passwordless switch to user2 using the below command.

    ssh user2@server1
    Note: the above commands switches user1 to user2 without the password [due to key exchange] however, I am not able to accomplish the same using java.

    Kindly help.
    Last edited by mohtashims; 08-21-2013 at 05:00 PM.

  2. #2
    radish is offline Member
    Join Date
    Aug 2013
    Posts
    16
    Rep Power
    0

    Default Re: Need code Snippet to switch users in unix

    Untested but along the lines of second example...
    java - Process Runtime pass input - Stack Overflow

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: Need code Snippet to switch users in unix

    See one of the java SSH libraries like JSch.

  4. #4
    mohtashims is offline Member
    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Default Re: Need code Snippet to switch users in unix

    Are you sure JSCH works ? Can you give me a small POJO so that I can test switching users in JSCH. One of my friend tried using JSCH and he says it does not HELP !!

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: Need code Snippet to switch users in unix

    You use it to login as the user you wish to "switch" to. NO module will allow you, on a remote system, to "switch users" with impunity. THAT would be a HUGE security hole.

    And, yes I KNOW that JSch works, I have used it fairly often in the past, and their site (but mainly the examples that come with the software) contains many "small POJOs".
    gimbal2 likes this.

Similar Threads

  1. Replies: 1
    Last Post: 10-25-2012, 12:59 AM
  2. Code snippet pls?
    By Srinivas0615 in forum New To Java
    Replies: 1
    Last Post: 07-29-2011, 11:32 PM
  3. code executing on windows/unix box
    By nn12 in forum New To Java
    Replies: 4
    Last Post: 04-07-2011, 02:26 AM
  4. Code compiles in/runs in IDE but not on UNIX system
    By Unclejunebug in forum New To Java
    Replies: 7
    Last Post: 10-08-2009, 09:35 AM
  5. Help with Switch string code
    By toby in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •