Trying to ssh as another user and cd to directory


 
Thread Tools Search this Thread
Top Forums Programming Trying to ssh as another user and cd to directory
# 1  
Old 12-10-2012
Trying to ssh as another user and cd to directory

I can ssh to another directory by doing the following:
Code:
 
for server in server1; do ssh -t $server1 "cd /tmp; 'ls'";done

However, if I try to do it as another user it fails:
I have tried:


Code:
 
for server in server1
do
dir=$(su - nbadaccount -c "ssh $server `cd '/tmp/TSTCON'` " )
pwd
done
 
for server in server1; do su nbadaccount -c "ssh -t $server "cd /tmp 'ls'"";done
 
for server in server1; do su nbadaccount -c ssh -t $server "cd /tmp; 'ls'";done

and a variety of other methods. The most I can get it to do is to ssh to the server but it never changes directories. Does anybody have any idea how to do this? Thanks in advance for any help.

---------- Post updated Dec 10th, 2012 at 10:44 AM ---------- Previous update was Dec 9th, 2012 at 10:00 PM ----------

Actually I decided to use the find command to find what I was looking for but I cannot get it to work with regex, though without ssh, it DOES work with regex:

Code:
 
varx=$(su nbadmin -c "ssh server1 'find /tmp/TSTCON01 -type d -name '*[0-9][0-9]*''");echo $varx

This does not work but if I run this command it does work:

Code:
 
server1>find /tmp/TSTCON01 -name "*[0-9][0-9]*" -type d"

it should print 1353000000 and it does as long as I am not running ssh. Anyone know why the regex is being lost?

Last edited by Scott; 12-10-2012 at 11:53 AM.. Reason: Please use code tags
# 2  
Old 12-10-2012
Define 'does not work'

What error do you get?

Do you have ssh keys set up on the remote servers?
# 3  
Old 12-10-2012
Code:
varx=$(su nbadmin -c "ssh server1 'find /tmp/TSTCON01 -type d -name \"*[0-9][0-9]*\"'")

This User Gave Thanks to elixir_sinari For This Post:
# 4  
Old 12-10-2012
This account does have permission to ssh to the servers and does not give errors with other commands. It has keys set up. I get the message

find: bad option 1143000000
find: [-H | -L] path-list predicate-list

---------- Post updated at 11:37 AM ---------- Previous update was at 11:05 AM ----------

This worked! Thanks, Elixer!Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

SunOS confusing root directory and user home directory

Hello, I've just started using a Solaris machine with SunOS 5.10. After the machine is turned on, I open a Console window and at the prompt, if I execute a pwd command, it tells me I'm at my home directory (someone configured "myuser" as default user after init). ... (2 Replies)
Discussion started by: egyassun
2 Replies

2. Shell Programming and Scripting

[SSH] Accessing remote directory with user-passed path

Hi everybody, Currently, I have a script which access a remote computer via SSH, go to a folder already defined in the code and then executes a program in it, just like that: ssh user@host << EOI cd path ./file EOI It executes fine, but now I want to pass an argument in the command... (2 Replies)
Discussion started by: lgb3
2 Replies

3. AIX

passwordless entry using ssh from one user to a different user on the same server

Hi, We have a requirement to do passwordless entry from one user to a different user on the same AIX server using ssh keys. Can some one help me with this? Thanks in advance, Panditt (3 Replies)
Discussion started by: deshaipet
3 Replies

4. Red Hat

Cannot ssh for a user

This is the entry when I tail /var/log/secure when I ssh for user "nightly"... Aug 4 03:19:48 itanium2 sshd: Illegal user nightly from ::ffff:10.91.220.35 Aug 4 03:20:10 itanium2 sshd: Failed password for illegal user nightly from ::ffff:10.91.220.35 port 32862 ssh2 What could be... (3 Replies)
Discussion started by: kirtikjr
3 Replies

5. UNIX for Dummies Questions & Answers

change user> to user@host> ssh prompt

Hi, I was wondering how to change the prompt for my ssh login. At the moment it is like user> while I'd like it to be as user@host> It is in the .bash_profile or .ssh ??? Thanks (2 Replies)
Discussion started by: pmasterkim
2 Replies

6. Solaris

Restricting SFTP user to a defined directory and home directory

Hi, I've created solaris user which has both FTP and SFTP Access. Using the "ftpaccess" configuration file options "guest-root" and "restricted-uid", i can restrict the user to a specific directory. But I'm unable to restrict the user when the user is logged in using SFTP. The aim is to... (1 Reply)
Discussion started by: sftpuser
1 Replies

7. UNIX for Advanced & Expert Users

.SSH directory not created

I have created a new user account on my openssh system.But the .ssh directory was not created under my home dir home/A00d56/. Could any one please suggest me whether the .ssh directory will be created automatically when we add the new user or we need to manually create that after? The use of... (3 Replies)
Discussion started by: srrao.ch
3 Replies

8. UNIX for Dummies Questions & Answers

.ssh directory not created

I have created a new user account on my openssh system.But the .ssh directory was not created under my home dir home/A00d56/. Could any one please suggest me whether the .ssh directory will be created automatically when we add the new user or we need to create that after? The use of this new... (3 Replies)
Discussion started by: srrao.ch
3 Replies

9. UNIX for Dummies Questions & Answers

.ssh directory question (Can i move it)

Hi All, pn:/wrk/an/tran/cr>) ls -ld .ssh drwx------ 2 crcv1ftp canusr 96 May 2 2007 .ssh I had .ssh directory inside a directory . When i trying to do find and delete automatic script . The find comman is failing saying it dont have permision to read .ssh . Can i move... (4 Replies)
Discussion started by: arunkumar_mca
4 Replies

10. UNIX for Advanced & Expert Users

ssh home directory permission

Hi All, I am using sftp to transfer files between two unix machines. As per my knowledge, in order to use public key authentication, the remote user's home directory permission should be set to 750 ( basically group and others should not have write permission ). Is there any way to over ride... (1 Reply)
Discussion started by: shihabvk
1 Replies
Login or Register to Ask a Question