Help in creating Sudo ssh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in creating Sudo ssh script
# 1  
Old 07-23-2014
Help in creating Sudo ssh script

Hi Experts,

I am new to Shell scripting. I want to login to a server using a script. The normal command I use is --> sudo ssh <Servername> . when i tried putting this into a txt format file and tried running, it throw an error "can't execute". I am an Admin and i have root access. Any help would be highly appreciated.
# 2  
Old 07-23-2014
Hi, copy and paste your script into this forum.
# 3  
Old 07-23-2014
Why are you using sudo to run the ssh command?
# 4  
Old 07-23-2014
Quote:
Originally Posted by Tom1989
Hi Experts,

when i tried putting this into a txt format file and tried running, it throw an error "can't execute".
how are you running it? if ./script then you must give exe permissions using chmod to it before running.
# 5  
Old 07-23-2014
Quote:
Originally Posted by Tom1989
Hi Experts,

I am new to Shell scripting. I want to login to a server using a script. The normal command I use is --> sudo ssh <Servername> .
Why run ssh as root? Why not just log in as root -- or better yet, don't. Does what you're doing really need root access?
# 6  
Old 07-24-2014
I am trying to setup keys between 2 unix servers automatically. Thats what i am trying to do. Script should get source and destination server from me and shoudld login automatically.

---------- Post updated at 11:58 PM ---------- Previous update was at 11:51 PM ----------

Quote:
Originally Posted by busi386
Hi, copy and paste your script into this forum.
I am using this command inside the script,just to verify if it works.

#! /bin/sh

--> ssh user@machine
asking password
--> sudo ssh user@machine
asking password.

I don't want to use -->sshpass -p<password> ssh user@machine because its secure and i dont want to save the password.

---------- Post updated 07-24-14 at 12:05 AM ---------- Previous update was 07-23-14 at 11:58 PM ----------

Quote:
Originally Posted by Corona688
Why run ssh as root? Why not just log in as root -- or better yet, don't. Does what you're doing really need root access?
I am setting ssh keys between 2 *nix servers. Since I am an Security Administrator i need to set up lot of keys, so trying ti automate.

---------- Post updated at 01:47 AM ---------- Previous update was at 12:05 AM ----------

Quote:
Originally Posted by prvnrk
how are you running it? if ./script then you must give exe permissions using chmod to it before running.
yes i did -->chmod +x myscript
# 7  
Old 07-25-2014
Quote:
Originally Posted by Tom1989
I am setting ssh keys between 2 *nix servers. Since I am an Security Administrator i need to set up lot of keys, so trying ti automate.
You don't need root for this, though. You can just do ssh root@host without needing to run ssh as root.

But permitting root login for ssh is dicey. People will be trying to crack the password on that, best not to let them even try. What I generally do is:

Code:
ssh username@host sudo ...

where 'username' is set up to allow login with a key and sudo configured to allow that username.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Require help in creating a Sudo/Shell script

Hello Friends, I have a scenario to create a script, I know many of you feel this as simple script. I am not much familiar with unix scripting, please help me out. Situation:- 1. I have a list of config files like 40+ would be getting deployed in the /app/abcd/src/Config/ (This will... (2 Replies)
Discussion started by: ganjvin
2 Replies

2. Shell Programming and Scripting

Running Local Script from SSH with SUDO

Hello, I know for SSH'ing and running a local script is... ssh -t user@servername < /path/to/localscript.sh and with SSH'ing and SUDO'ing is... ssh -t user@servername "sudo -u username ls -l /home/username" My inquiry is how can I combine both, by SSH'ing and SUDO'ing but running... (4 Replies)
Discussion started by: WPGPoseidon
4 Replies

3. Cybersecurity

Help on Ssh using sudo

I'm confused in the configuration of sudoers for one group of users. The users need to execute a app from a remote machine, in this local machine they want me to allow ssh for them using sudo for eg. sudo -u admin ssh -X euadmin@<IP address of remote> <remote script which opens a gui> It... (1 Reply)
Discussion started by: anandk
1 Replies

4. Shell Programming and Scripting

Ssh & sudo

when the following command is issued the command prompt is received, how do I get past this? ssh -t usera@hosta sudo su - userb -c id (4 Replies)
Discussion started by: squrcles
4 Replies

5. Programming

Using Commands over SSH using Sudo

Is there a way to transfer my sudo password via ssh so that I can copy files remotely and pass them locally, so: cat sudo-passwd-file|ssh -t user@10.7.0.180 'sudo find / -depth|cpio -oacv|gzip' > /path/to/dir/file.cpio.gz I am in the process of a creating a script. Everytime I try and just... (16 Replies)
Discussion started by: metallica1973
16 Replies

6. Shell Programming and Scripting

ssh foo.com sudo command - Prompts for sudo password as visible text. Help?

I am writing a BASH script to update a webserver and then restart Apache. It looks basically like this: #!/bin/bash rsync /path/on/local/machine/ foo.com:path/on/remote/machine/ ssh foo.com sudo /etc/init.d/apache2 reloadrsync and ssh don't prompt for a password, because I have DSA encryption... (9 Replies)
Discussion started by: fluoborate
9 Replies

7. UNIX for Advanced & Expert Users

ssh and sudo login

Hi, I am trying to execute some command, via ssh and sudo. Here is what i want to do. ssh localhost | sudo su - ldaprole | ls -ltrh However, this command gives me listing of my home directory, and not of ldaprole. If I logic directly, when i perform sudo su - ldaprole, it... (5 Replies)
Discussion started by: john_prince
5 Replies

8. UNIX for Advanced & Expert Users

sudo and ssh

Hi, I would like to know how i can perform a task, while performing ssh, sudo and command at the same time. What I generally do is I ssh to the server, where i created private and public, so it does not prompt me for password all the time. Then i need to run "sudo su - ldaprole" to get into... (9 Replies)
Discussion started by: john_prince
9 Replies

9. UNIX for Advanced & Expert Users

sudo and ssh

Hello, Can you config sudo to use the passphrase in the user ssh-key instead of the one in the passwd? Some users do not have local passwords on the system and instead of adding the NOPASSWD in sudoers I would like the solution I asked about above. Thx Jocke (3 Replies)
Discussion started by: jOOc
3 Replies

10. UNIX for Advanced & Expert Users

xwindows over ssh after sudo?

ok...I'm stumped on this one. I cannot figure out how to carry over my environment variables with a sudo command. I need to install an application under root and only have sudo access to get there. I can use ssh -Y <host> and launch an xwindows session successfully as myself but as soon as I sudo... (3 Replies)
Discussion started by: scottsl
3 Replies
Login or Register to Ask a Question