LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-22-2019, 12:51 AM   #1
sampy12345
LQ Newbie
 
Registered: Jul 2017
Posts: 12

Rep: Reputation: Disabled
Linux switching User


Hi all,

I am trying to write a script for copying a file from one server to another but unable to achive due to user access issue.

My Linux connectivity as below

I need to connect to one user and from there i need to switch the user but i am able to connect to the service with one user but the user doesn't have access to run the script and after swtiching to another user only the script will run with sudo access . Kidnly help me how to achieve ( we can't add the 1st user in sudoer file due to security policy)

below is the one i am trying to connect to the user( this is successfull but from here i need to switch to another user and run the script)

sshpass -p 'Feb@2019' ssh -tt vdimi01@0.0.0.0 'echo 'Feb@2019' | sudo -S -s /bin/bash -c "/usr/local/datamove.sh"'
 
Old 02-22-2019, 08:01 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 22,306

Rep: Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007
Quote:
Originally Posted by sampy12345 View Post
Hi all,
I am trying to write a script for copying a file from one server to another but unable to achive due to user access issue. My Linux connectivity as below

I need to connect to one user and from there i need to switch the user but i am able to connect to the service with one user but the user doesn't have access to run the script and after swtiching to another user only the script will run with sudo access . Kidnly help me how to achieve ( we can't add the 1st user in sudoer file due to security policy)

below is the one i am trying to connect to the user( this is successfull but from here i need to switch to another user and run the script)

sshpass -p 'Feb@2019' ssh -tt vdimi01@0.0.0.0 'echo 'Feb@2019' | sudo -S -s /bin/bash -c "/usr/local/datamove.sh"'
Related to this other thread?? https://www.linuxquestions.org/quest...pt-4175647798/

And what happens when you run things as above? You don't say what error(s)/problem(s) you're getting, and you never really followed up in that other thread, either. Not sure why you're using sshpass, when you can much more easily do a keyswap, and execute the remote bash script directly. And you may be making this more complicated than it needs to be. The bash script probably only needs sudo access for some of the commands in it...so why not just put "sudo ...." in front of those commands in the script, so it runs for anyone?
 
Old 02-25-2019, 07:46 AM   #3
sampy12345
LQ Newbie
 
Registered: Jul 2017
Posts: 12

Original Poster
Rep: Reputation: Disabled
Thanks for the response TB0ne

the one which is posted previously is different and here my requirement is different.

Here my requirement is to run a script in a remote server after switching the user.

sshpass is used to connect to another system and run a script or command. Here after connecting to the server i am getting permission denied error.

I just want the syntax for connecting a server switching the user and running the script.

I didn't understand how keyswap fullfills my requirement
 
Old 02-25-2019, 08:06 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 22,306

Rep: Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007Reputation: 6007
Quote:
Originally Posted by sampy12345 View Post
Thanks for the response TB0ne
the one which is posted previously is different and here my requirement is different.
Oh?? How so? In your other thread you were asking for a shell script that took command-line variables. Here, you're trying to put a command line that looks really similar as a command line argument.
Quote:
Here my requirement is to run a script in a remote server after switching the user. sshpass is used to connect to another system and run a script or command. Here after connecting to the server i am getting permission denied error. I just want the syntax for connecting a server switching the user and running the script.
There is no syntax; think about what you're doing. Once you 'switch users' the parent shell goes into the background...meaning the commands you're passing are all going to WAIT until that shell exits.

AGAIN: why can't you just put "sudo" statements in front of the lines in your script that need root/other access, and use sudo for what it was intended for?
Quote:
I didn't understand how keyswap fullfills my requirement
You don't need sshpass or most of what your command line is right now. To run a remote script, the entire command line would be:
Code:
ssh user@host "/some/path/to/script"
..that's it. Again, put sudo in front of whatever commands need sudo/different access in your 'datamove.sh' script.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find the base / original user after switching in linux rao1995 Linux - Newbie 3 01-04-2019 05:42 AM
[SOLVED] switching mouse button won't take effect/switching language won't apply/zukitwo theme looking rough vienswuer Linux - Distributions 1 05-16-2016 07:32 AM
KDE 3.3 Bad Monitor Switching on Desktop Switching Inchoate Linux - Software 1 05-25-2005 03:00 PM
Newbie to Linux. Was a Windows User NOW Switching to Mandrake. pangwl00 Mandriva 4 12-07-2004 09:55 AM
"Fast User Switching" (XP Style) in Linux... cedillo Linux - Newbie 3 12-18-2002 01:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration