scp file to server with user different than ssh login
up vote
1
down vote
favorite
I need to copy file somefile.jar
from local computer (cygwin) to remote server.local
. I have an ssh login corp
to server.local
that a sudoer on server.local
. I need to place the file to folder /opt/alice/libs/
owned by another user:
[corp@server.local ~]$ ls -ld /opt/alice/libs
drwxr-xr-x 2 alice alice 12288 Apr 13 11:09 /opt/alice/libs
I cannot direct upload file to chosen directory because of insufficient rights. So, my way to copy has few steps with /tmp/
on server.local
$ scp ./somefile.jar corp@server.local/tmp/
$ ssh copr@server.local
Last login: Thu Apr 12 18:05:41 2018 from 192.168.87.34
[corp@server.local ~]$ sudo chown alice:alice /tmp/somefile.jar
[corp@server.local ~]$ sudo -u alice mv /tmp/somefile.jar /opt/alice/libs/
Is there a shorter way to perform the upload?
If a tool does not exist to achieve my purposes, maybe it is possible to make a *.sh
script that include all of these operations?
scp file-copy chown
add a comment |
up vote
1
down vote
favorite
I need to copy file somefile.jar
from local computer (cygwin) to remote server.local
. I have an ssh login corp
to server.local
that a sudoer on server.local
. I need to place the file to folder /opt/alice/libs/
owned by another user:
[corp@server.local ~]$ ls -ld /opt/alice/libs
drwxr-xr-x 2 alice alice 12288 Apr 13 11:09 /opt/alice/libs
I cannot direct upload file to chosen directory because of insufficient rights. So, my way to copy has few steps with /tmp/
on server.local
$ scp ./somefile.jar corp@server.local/tmp/
$ ssh copr@server.local
Last login: Thu Apr 12 18:05:41 2018 from 192.168.87.34
[corp@server.local ~]$ sudo chown alice:alice /tmp/somefile.jar
[corp@server.local ~]$ sudo -u alice mv /tmp/somefile.jar /opt/alice/libs/
Is there a shorter way to perform the upload?
If a tool does not exist to achieve my purposes, maybe it is possible to make a *.sh
script that include all of these operations?
scp file-copy chown
If you can't connect as alice to the server, then yes, you found the shortest way to do that
– Félicien
Apr 13 at 8:45
@Félicien - Thank you. I cannot login asalice
user
– Loom
Apr 13 at 8:46
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I need to copy file somefile.jar
from local computer (cygwin) to remote server.local
. I have an ssh login corp
to server.local
that a sudoer on server.local
. I need to place the file to folder /opt/alice/libs/
owned by another user:
[corp@server.local ~]$ ls -ld /opt/alice/libs
drwxr-xr-x 2 alice alice 12288 Apr 13 11:09 /opt/alice/libs
I cannot direct upload file to chosen directory because of insufficient rights. So, my way to copy has few steps with /tmp/
on server.local
$ scp ./somefile.jar corp@server.local/tmp/
$ ssh copr@server.local
Last login: Thu Apr 12 18:05:41 2018 from 192.168.87.34
[corp@server.local ~]$ sudo chown alice:alice /tmp/somefile.jar
[corp@server.local ~]$ sudo -u alice mv /tmp/somefile.jar /opt/alice/libs/
Is there a shorter way to perform the upload?
If a tool does not exist to achieve my purposes, maybe it is possible to make a *.sh
script that include all of these operations?
scp file-copy chown
I need to copy file somefile.jar
from local computer (cygwin) to remote server.local
. I have an ssh login corp
to server.local
that a sudoer on server.local
. I need to place the file to folder /opt/alice/libs/
owned by another user:
[corp@server.local ~]$ ls -ld /opt/alice/libs
drwxr-xr-x 2 alice alice 12288 Apr 13 11:09 /opt/alice/libs
I cannot direct upload file to chosen directory because of insufficient rights. So, my way to copy has few steps with /tmp/
on server.local
$ scp ./somefile.jar corp@server.local/tmp/
$ ssh copr@server.local
Last login: Thu Apr 12 18:05:41 2018 from 192.168.87.34
[corp@server.local ~]$ sudo chown alice:alice /tmp/somefile.jar
[corp@server.local ~]$ sudo -u alice mv /tmp/somefile.jar /opt/alice/libs/
Is there a shorter way to perform the upload?
If a tool does not exist to achieve my purposes, maybe it is possible to make a *.sh
script that include all of these operations?
scp file-copy chown
scp file-copy chown
edited Dec 5 at 23:30
Jeff Schaller
37.4k1052121
37.4k1052121
asked Apr 13 at 8:35
Loom
1,03021928
1,03021928
If you can't connect as alice to the server, then yes, you found the shortest way to do that
– Félicien
Apr 13 at 8:45
@Félicien - Thank you. I cannot login asalice
user
– Loom
Apr 13 at 8:46
add a comment |
If you can't connect as alice to the server, then yes, you found the shortest way to do that
– Félicien
Apr 13 at 8:45
@Félicien - Thank you. I cannot login asalice
user
– Loom
Apr 13 at 8:46
If you can't connect as alice to the server, then yes, you found the shortest way to do that
– Félicien
Apr 13 at 8:45
If you can't connect as alice to the server, then yes, you found the shortest way to do that
– Félicien
Apr 13 at 8:45
@Félicien - Thank you. I cannot login as
alice
user– Loom
Apr 13 at 8:46
@Félicien - Thank you. I cannot login as
alice
user– Loom
Apr 13 at 8:46
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
If you want to do a simple script, assuming your sudo does not need a password, you could pipe the data across:
tar cf - ./somefile.jar |
ssh -t copr@server.local sudo -u alice tar xf - -C /opt/alice/libs/
The -C
changes directory before extracting the file. If your tar does not have this, add an explicit cd /opt/alice/libs/
first.
add a comment |
up vote
0
down vote
That is most likely the only way to do that.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
If you want to do a simple script, assuming your sudo does not need a password, you could pipe the data across:
tar cf - ./somefile.jar |
ssh -t copr@server.local sudo -u alice tar xf - -C /opt/alice/libs/
The -C
changes directory before extracting the file. If your tar does not have this, add an explicit cd /opt/alice/libs/
first.
add a comment |
up vote
2
down vote
If you want to do a simple script, assuming your sudo does not need a password, you could pipe the data across:
tar cf - ./somefile.jar |
ssh -t copr@server.local sudo -u alice tar xf - -C /opt/alice/libs/
The -C
changes directory before extracting the file. If your tar does not have this, add an explicit cd /opt/alice/libs/
first.
add a comment |
up vote
2
down vote
up vote
2
down vote
If you want to do a simple script, assuming your sudo does not need a password, you could pipe the data across:
tar cf - ./somefile.jar |
ssh -t copr@server.local sudo -u alice tar xf - -C /opt/alice/libs/
The -C
changes directory before extracting the file. If your tar does not have this, add an explicit cd /opt/alice/libs/
first.
If you want to do a simple script, assuming your sudo does not need a password, you could pipe the data across:
tar cf - ./somefile.jar |
ssh -t copr@server.local sudo -u alice tar xf - -C /opt/alice/libs/
The -C
changes directory before extracting the file. If your tar does not have this, add an explicit cd /opt/alice/libs/
first.
answered Apr 14 at 19:01
meuh
31.2k11754
31.2k11754
add a comment |
add a comment |
up vote
0
down vote
That is most likely the only way to do that.
add a comment |
up vote
0
down vote
That is most likely the only way to do that.
add a comment |
up vote
0
down vote
up vote
0
down vote
That is most likely the only way to do that.
That is most likely the only way to do that.
answered Apr 13 at 8:46
Buddika
1324
1324
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f437471%2fscp-file-to-server-with-user-different-than-ssh-login%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If you can't connect as alice to the server, then yes, you found the shortest way to do that
– Félicien
Apr 13 at 8:45
@Félicien - Thank you. I cannot login as
alice
user– Loom
Apr 13 at 8:46