Sponsored Content
Full Discussion: SSH and SCP HELP
Top Forums Shell Programming and Scripting SSH and SCP HELP Post 302338749 by mglenney on Tuesday 28th of July 2009 08:13:56 PM
Old 07-28-2009
Unless something has changed that I don't know about, you cannot su to another user when executing a command via ssh. Something about the su command needing you to be assigned a tty.

What you CAN do is sudo commands. So if you need to run something as root and you have sudo rights your script can do this:

Code:
ssh me@host "sudo somecommand"

That will ssh to "host" and execute "somecommand" as root.

Also, your script examples are a little flawed. You have ssh on it's own line and then some commands after that. That's now how that works. In your examples, you would ssh to the box in question and once you exited that box the remainder of the commands would be run. You can put your commands into a script on the remote server and then execute that script:

Code:
ssh me@host "/path/to/script"

NOTE: I keep putting the command in quotes but that's not required unless it contains spaces.

Even if you do this you're still going to have issues with switching users (I believe. you'll have to try it). If you need all the commands in the remote switch to run as root you can just "sudo /path/to/script".
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SSH and SCP

The following ksh script is trying to get a file's cksum then, scp it over to a remote machine - get the cksum there and then compare the two cksums to make sure they match. I am having problems setting a variable on the remote host where it can be read locally. Is this even possible - reading a... (1 Reply)
Discussion started by: berrean
1 Replies

2. BSD

SCP and ssh

I can't get ssh ans scp to work between to host on my network. I am prompted for the password and it isn't accepting the password and I know the password is correct because I am using the root password. What do I need to do to get ssh working between the two host and scp. I can putty into the... (2 Replies)
Discussion started by: rbizzell
2 Replies

3. Shell Programming and Scripting

ssh/scp - can you specify timeout?

I am scp'ing a file from a server (servera) to my server (serverb) If servera is down - the scp never times out ... it just hangs eternally.. It is possible to specify a timeout in my script - so if scp fails/hang for more than 60 seconds I assume its failed ? I am aware there is some... (3 Replies)
Discussion started by: frustrated1
3 Replies

4. AIX

ssh and scp in aix 4.3.3

I'm using scp to copy files to another company via our 4.3.3 server. I am having transfer problems right at the transfer point in scp. Below are 2 debug outputs showing the bottleneck. The lower level debug preceeds the higher level debug output. It just seems to stop and refuses to transfer... (0 Replies)
Discussion started by: oldogbert
0 Replies

5. Solaris

SSH/SCP Question

Thanks to this forum, I was able to get a program running that uses SSH to control programs running on other hosts. Now I'd like to enhance it. The control program on the target hosts occassionally needs to be updated. Updating the menu program on the source host is easy as it is on one host. ... (1 Reply)
Discussion started by: PabloCruise77
1 Replies

6. UNIX for Advanced & Expert Users

Simulating scp through ssh

How to simulate scp command using ssh? (5 Replies)
Discussion started by: vickylife
5 Replies

7. Solaris

SCP & SSH errors

Hi I am trying to scp a file between to servers (both on same subnet and can see each other). However, whenever I try I get the following error: ld.so.1: ssh: fatal: relocation error: file /usr/local/bin/ssh: symbol EVP_CIPHER_CTX_key_length: referenced symbol not found lost connection I... (4 Replies)
Discussion started by: skewbie
4 Replies

8. UNIX for Advanced & Expert Users

Problem with ssh and scp

Hi there, I'm working with two linux servers and if I use ssh to connect from 1 to 2 everything works fine ( ..as usual:rolleyes:), while if I try to connect via ssh or to copy files through scp (as I usually do...) from 2 to 1, after the password I get this message: Connection closed by... (6 Replies)
Discussion started by: Giordano Bruno
6 Replies

9. Solaris

ssh and scp not working

Dear All, whenever i try the command ssh , it is giving the below error. ld.so.1: ssh: fatal: relocation error: file /usr/bin/ssh: symbol SUNWcry_installed: referenced symbol not found Killed For SCP also the same error is coming. Pl reply me if you have answers. Rj (4 Replies)
Discussion started by: jegaraman
4 Replies

10. UNIX for Beginners Questions & Answers

Ssh find and scp

Hello All, I have a requirement to copy few files from remote server to local, and below are the sequence ssh to the remote host finding the files with the specific condition once found scp to the local server path for (( i=0; i<${tLen}; i++ )) do ssh... (1 Reply)
Discussion started by: nextStep
1 Replies
SSH-ARGV0(1)						    BSD General Commands Manual 					      SSH-ARGV0(1)

NAME
ssh-argv0 -- replaces the old ssh command-name as hostname handling SYNOPSIS
hostname | user@hostname [-l login_name] [command] hostname | user@hostname [-afgknqstvxACNTX1246] [-b bind_address] [-c cipher_spec] [-e escape_char] [-i identity_file] [-l login_name] [-m mac_spec] [-o option] [-p port] [-F configfile] [-L port:host:hostport] [-R port:host:hostport] [-D port] [command] DESCRIPTION
ssh-argv0 replaces the old ssh command-name as hostname handling. If you link to this script with a hostname then executing the link is equivalent to having executed ssh with that hostname as an argument. All other arguments are passed to ssh and will be processed normally. OPTIONS
See ssh(1). FILES
See ssh(1). AUTHORS
OpenSSH is a derivative of the original and free ssh 1.2.12 release by Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo de Raadt and Dug Song removed many bugs, re-added newer features and created OpenSSH. Markus Friedl contributed the support for SSH protocol versions 1.5 and 2.0. Jonathan Amery wrote this ssh-argv0 script and the associated documentation. SEE ALSO
ssh(1) Debian Project September 7, 2001 Debian Project
All times are GMT -4. The time now is 02:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy