Switching between users on UNIX without private key (intentional)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Switching between users on UNIX without private key (intentional)
# 1  
Old 10-04-2012
Data Switching between users on UNIX without private key (intentional)

Hello Everyone,

I'm new to unix and having trouble with switching users
s_user='sample_user', I need to connect to a remote server using the user "sampleuser" copy files on that remote server. However I am not allowed to add a private key to that same server nor add scripts on sampleuser's directory so this is the most plausible solution I could come up with.

########start#########
s_user='sampleuser'

su - $s_user

########end###########

it does prompts me for the password of that user but it terminates and has this "error"

./sample.sh[10]: 741 Killed

Please help me Smilie

And also it would be nice if you could with ideas in making a login 'prompt' for users. Thanks Very Much
# 2  
Old 10-04-2012
You could use ftp to transfer the files, setup the user and password in your $HOME/.netrc file:

Code:
machine remote_server
login sample_user
password Secret

Then just use something link the below to fetch the files:
Code:
ftp remote_server <<EOF
   cd /path/to/file
   get filename
   quit
EOF

Make sure the .netrc file has 600 permissions or ftp will refuse to use it (also you don't want other users being able to see the password).
# 3  
Old 10-04-2012
Hmm I'm a bit confused with your example above. Will the "password" there be the one that switches me to sampleuser or the one that connects me to the server. Before, the usual step for me is to switch to sampleuser first then connect to the remote server. This is because sampleuser has a ssh key on that remote server while my username has none. Sorry if I'm such a noob :P cheers!
# 4  
Old 10-04-2012
OK now I think I understand what you are trying to do.

Is it acceptable to copy sampleuser's id_rsa (private key) and id_rsa.pub to your own .ssh directory?

If so you can then use the ssh/sftp -i identity_file command line option to swap in these certificates for transfers to the remote_host eg:

Code:
sftp -i $HOME/.ssh/sample_user_id_rsa remote_user@remote_host

# 5  
Old 10-04-2012
T---T sadly no. I ain't allowed to do that. Actually I've also thought of that before since it might save me the hassle of coding and the torment that usually comes with it. Smilie

I don't know what's wrong with my script, I believe it's possible to switch into a certain user and use it within a shell script since I've seen some on the internet. (although just parts of it)

It's been a long time since I've programmed something or even wrote a script. And I'm a newbie with unix. Do you know any online links that may prove useful to me? I really appreciate your help! THANKS! Smilie
# 6  
Old 10-04-2012
As far as I see it your have 4 options:
  1. get your own copy of sampleuser's public/private keys (you've ruled this out already)
  2. get sysadmin to allow your user to execute sudo without password for a given command/script as user sampleuser
  3. get your own public key added to sampleuser's .ssh/authorized file and use ssh to localhost as sampleuser to run the script/sftp needed
  4. Create a cron job for sampleuser that does any queued transfers for you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Private and public key encryption

Hi, we have private and public key, encrypt file using public and want to decrypt using private key. can you please advise below commands are correct or other remedy if unix have? encrypt -a arcfour -k publickey.asc -i TESTFILE.csv -o TESTFILE00.csv decrypt -a arcfour -k privatekey.asc... (2 Replies)
Discussion started by: rizwan.shaukat
2 Replies

2. OS X (Apple)

Using a private key with SSH in terminal

Before you get the wrong idea, I am not looking for how to generate one. I have a key from a server admin but I can't figure out how to use it in OS X. I have the key, the address and everything I should need but there doesn't seem to be a step by step on how to install the key and use it in... (4 Replies)
Discussion started by: kylebellamy
4 Replies

3. Shell Programming and Scripting

Private Key

I have two types of files pubring.pkr secring.skr secring.skr is encrypted and not able to read. How can i read secring.skr in text format after decrypting ? is there any way of decrypting this file? Unix HP - UX Version. (4 Replies)
Discussion started by: airesh
4 Replies

4. UNIX for Dummies Questions & Answers

Secure private key

Hello all, We have unix environment and we would like to use ssh public and private key to move between server using ssh. I do know how to test this and have it up and running on some sandbox...but my question is how would one secure the PRIVATE KEY....we are not using a passphrase...and i know... (1 Reply)
Discussion started by: abdul.irfan2
1 Replies

5. UNIX for Dummies Questions & Answers

Extracting a Private key from a keystore?

Hi everyone! I know you can extract public keys from a keystore using the keytool command. But what is the process to extract a private key from a jks keystore and import into another jks keystore using keytool? Any guidance would be greatly appreciated! I can't seem to find anything, I do... (0 Replies)
Discussion started by: Keepcase
0 Replies

6. Shell Programming and Scripting

how to ssh to remote unix machines using private/public key

hello, iam able to ssh to a linux server from a linux server called "machine1" using the private/public key method, so I dont need to enter any password when I run my script but iam not able to ssh from machine1 to a UNIX server, access is denied. note that I am using an application id which is... (6 Replies)
Discussion started by: wydadi
6 Replies

7. Solaris

Multiple private key to be uploaded

I would like to ask if you have a procedure on how to upload multiple private key for multiple users in solaris? I was only able to add one but when I tried to add several key, it fails. example: a. user1: user1.ppk b. user2: user2.ppk Each with different password on the server. Pls advise (6 Replies)
Discussion started by: lhareigh890
6 Replies

8. Shell Programming and Scripting

Rename .pub and private key

I wish to generate a id_dsa.pub and id_dsa (Public and Private Key) in a common user group. I have checked the .ssh directory and i have already found id_dsa.pub and id_dsa existing. Is that OK if i create both the keys in my home direcotry, rename it to jjj.pub and jjj and move to Common user... (1 Reply)
Discussion started by: vasuarjula
1 Replies

9. Windows & DOS: Issues & Discussions

Public/Private Key SSH from UNIX to Windows (Cygwin)

Hello all, I have a bit of trouble working a passwordless SSH from UNIX to Cygwin running windows 2k3. Here are some details. I AM able to SSH from the Windows box to the UNIX box using the keys. Also, I'm able to SSH from UNIX to Windows w/o the keys. However, when I try to do it with the keys... (9 Replies)
Discussion started by: kclerks11
9 Replies

10. Programming

Passphrase protection of private key

Hi all, I have written a Java program to generate RSA public and private keys. I am writing the keys to a file and reading from it when required to encryption or decryption. I want to protect the private key file using a passphrase. Can anyone tell me how to do it? :( Thanks. (2 Replies)
Discussion started by: Treasa
2 Replies
Login or Register to Ask a Question