ssh and sudo login


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users ssh and sudo login
# 1  
Old 01-25-2011
ssh and sudo login

Hi,

I am trying to execute some command, via ssh and sudo.

Here is what i want to do.

Code:
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 directly goes to ldaprole home.

Any help in this regard is appreciated.

Thanks. John
# 2  
Old 01-27-2011
Hi,

Why are you piping to ls? (this will get your home dir contents as you mentioned).

You could do the following the the effect you're after (but you'll have to add the -c flag for su to sudoers I suspect)

Code:
ssh localhost "sudo su - ldaprole -c \"ls -ltr\""

# 3  
Old 01-27-2011
Thanks for reply.

This command works, but i cannot excecute any command after i sudo to the role.

Code:
ssh -t localhost ' sudo su - ldaprole | id'

How to run command after i sudo to ldaprole.?
# 4  
Old 01-27-2011
I don't think you understand what | means. Do you really want to channel the text output of the su command into the id command? id reads no input, it just prints!

This will log you in as ldaprole, run something, then give you a prompt: $ ssh -t localhost 'sudo su - ldaprole -c "id ; exec bash"'

The -c tells su to run the given command after it. We're telling it to run id, then run a shell... Running a shell is crucial because without it, ssh and su will both consider themselves out of input and return without waiting.

Substitute your shell of choice for bash. Absolute paths preferred.

Last edited by Corona688; 01-27-2011 at 03:01 PM..
# 5  
Old 01-27-2011
Hi,

Actually i am not allowed to run with "-c", it says permission denied. and i believe it is not there in the sudo list. Do you know any other alternative for this.

Thanks, John.
# 6  
Old 01-28-2011
Hi John,

Please see my earlier post, specifically:

Quote:
Originally Posted by dsw
(but you'll have to add the -c flag for su to sudoers I suspect)
I suggest you request that your Sysadmin "does the needful", because sudo will consume arguments passed and check whether they correspond to your allowed entries in the sudoers file.
This User Gave Thanks to dsw For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automating su ( sudo ) login

Hi, I am planning to automate a deployment process and the below are the steps Connect from windows to Unix server Login with user name : admin and password After logging in , switch user to root to get additional privileges Perform actions on files and directories post switching to... (3 Replies)
Discussion started by: venkidhadha
3 Replies

2. 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

3. Shell Programming and Scripting

Need a script for sudo, login and output

Hello All , Hope everyone is doing great ! can someone help me for the below problem statement with the help of a script . 1. I am having couple of Linux Servers a. I need to login and need to do a sudo b. need to give a user id , which will take to user directory`s homedirectory... (1 Reply)
Discussion started by: radha254
1 Replies

4. UNIX for Dummies Questions & Answers

Passing password to sudo login

Hi All, I am trying use the below su command to execute a shell script using different user. Caould some one please help me out as to how to pass the pass the password when prompted or is there any way to execute the shell script using other user. I have had look at the other posts in forum... (1 Reply)
Discussion started by: abhi_n123
1 Replies

5. 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

6. UNIX for Dummies Questions & Answers

sudo login issue

I logged in through ssh, but can't re-login as root. sudo login Arch login: root Password: Login incorrect Arch login: But I am sure my password is right. Why? But on local tty1, this works. (2 Replies)
Discussion started by: vistastar
2 Replies

7. HP-UX

telnet login successful ,but ssh can not login

why I can login by telnet using root account but when i use login by ssh using root account it is not successful ,is it different password i am sure ssh service is started (2 Replies)
Discussion started by: alert0919
2 Replies

8. Shell Programming and Scripting

Issue in passing passwd to login into a sudo account

Hi Gurus, I have small issue... I used to pass the passwd for sudo commands like below, gzcat ~/passwd.gz | sudo su - <villin> >> eof ------ ----- ------ eof And it was able to login into "villin" sudo account successfully. But now, I'm using the same in another script for the... (2 Replies)
Discussion started by: raghu.iv85
2 Replies

9. 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

10. 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
Login or Register to Ask a Question