How to write to local machine from SSH?

Hello.
Since last few weeks, I have been doing SSH to a server using my local FreeBSD desktop. I am able to read/write, and do the stuff that I am permitted to including setting up crons, and few other kubernetes related stuff.

But around 3-4 days ago, I tried to download a file (using scp command) to my local directory. But I got "permission denied" error. I tried a few different things, including changing permissions of the local directory. Then I created a local user by the name "tools.kiranbot4", gave it appropriate permissions, but still I am getting following response:

tools.kiranbot4@tools-sgebastion-10:~$ touch /home/usernamekiran/KiranBOT/scripts/test.txt
touch: cannot touch '/home/usernamekiran/KiranBOT/scripts/test.txt': Permission denied
tools.kiranbot4@tools-sgebastion-10:~$


What should I do so that I would be able to copy files from the SSH terminal?

Regards,
usernamekiran.
 
That looks like a simple access permission issue. The communications protocol you use to login to the Unix host is not relevant. From the exact situation in which you used the touch(1) command above, show us the output of:
Code:
id
ls -lad /home/usernamekiran/KiranBOT/scripts/test.txt
ls -lad /home/usernamekiran/KiranBOT/scripts
ls -lad /home/usernamekiran/KiranBOT
ls -lad /home/usernamekiran/
ls -lad /home
ls -lad /
 
That looks like a simple access permission issue. The communications protocol you use to login to the Unix host is not relevant. From the exact situation in which you used the touch(1) command above, show us the output of:
Code:
id
ls -lad /home/usernamekiran/KiranBOT/scripts/test.txt
ls -lad /home/usernamekiran/KiranBOT/scripts
ls -lad /home/usernamekiran/KiranBOT
ls -lad /home/usernamekiran/
ls -lad /home
ls -lad /
Hi. Thanks for the response. Following is the output requested by you.
Code:
Last login: Sun Jul 30 16:52:08 2023 from <my IP address>
usernamekiran@tools-sgebastion-10:~$ become kiranbot4

tools.kiranbot4@tools-sgebastion-10:~$ id
uid=54990(tools.kiranbot4) gid=54990(tools.kiranbot4) groups=54990(tools.kiranbot4)

tools.kiranbot4@tools-sgebastion-10:~$ ls -lad /home/usernamekiran/KiranBOT/scripts/test.txt
ls: cannot access '/home/usernamekiran/KiranBOT/scripts/test.txt': Permission denied

tools.kiranbot4@tools-sgebastion-10:~$ ls -lad /home/usernamekiran/KiranBOT/scripts
ls: cannot access '/home/usernamekiran/KiranBOT/scripts': Permission denied

tools.kiranbot4@tools-sgebastion-10:~$ ls -lad /home/usernamekiran/KiranBOT
ls: cannot access '/home/usernamekiran/KiranBOT': Permission denied

tools.kiranbot4@tools-sgebastion-10:~$ ls -lad /home/usernamekiran/
drwx------ 6 usernamekiran wikidev 4096 Feb  4 08:23 /home/usernamekiran/

tools.kiranbot4@tools-sgebastion-10:~$ ls -lad /home
lrwxrwxrwx 1 root root 38 Mar 30  2021 /home -> /mnt/nfs/labstore-secondary-tools-home

tools.kiranbot4@tools-sgebastion-10:~$ ls -lad /
drwxr-xr-x 19 root root 4096 Jul 29 06:24 /

tools.kiranbot4@tools-sgebastion-10:~$

I ran the command scp /data/project/kiranbot4/scripts/test.txt /home/usernamekiran/KiranBOT/scripts/ on the SSH terminal, I am not sure if the terminal is trying to copy the file on my local machine, or on the remote path. I have same doubts with tools.kiranbot4@tools-sgebastion-10:~$ touch /home/usernamekiran/KiranBOT/scripts/test.txt Is it trying to touch "test.txt" on local machine, or on remote destination?
 
You are doing a local copy unless you specify user@host in the scp command.


“The source and target may be specified as a local pathname, a remote host
with optional path in the form [user@]host:[path]“
 
You are doing a local copy unless you specify user@host in the scp command.


“The source and target may be specified as a local pathname, a remote host
with optional path in the form [user@]host:[path]“
Hi. The main issue is, my key is configured for the user `usernamekiran`. After logging in, I have to switch by using
usernamekiran@tools-sgebastion-10:~$ become kiranbot4
So the following command does not work, as it expects the key for tools.kiranbot4 (or kiranbot4?)
tools.kiranbot4@tools-sgebastion-10:~$ scp tools.kiranbot4@login.<remote host>:/data/project/kiranbot4/scripts/test.txt /home/usernamekiran/KiranBOT/scripts/
tools.kiranbot4@login.<host>.org: Permission denied (publickey,hostbased).
 
Use the -i identity flag


-i identity_file
Selects the file from which the identity (private key) for public
key authentication is read. This option is directly passed to
ssh(1).
 
Use the -i identity flag


-i identity_file
Selects the file from which the identity (private key) for public
key authentication is read. This option is directly passed to
ssh(1).
Hi. I got following:
tools.kiranbot4@tools-sgebastion-10:~$ scp -i ~/.ssh/id_rsa /data/project/kiranbot4/scripts/test.txt /home/usernamekiran/KiranBOT/scripts
cp: failed to access '/home/usernamekiran/KiranBOT/scripts': Permission denied

I also tried tools.kiranbot4@tools-sgebastion-10:~$ scp /data/project/kiranbot4/scripts/test.txt ~/KiranBOT/scripts
and I got following error:
cp: cannot create regular file '/data/project/kiranbot4/KiranBOT/scripts': No such file or directory
From the error message, it is evident that command has been trying to copy the file on remote destination.

So I ran the following command:
scp /data/project/kiranbot4/scripts/test.txt /data/project/kiranbot4/logs/ and that command successfully copied the file in the remote "logs" directory.

Is it possible to explicitly specify to copy the content from remote, and to paste it on local machine?
 
? Here's how:
Code:
tools.kiranbot4@tools-sgebastion-10:~$ rm -rf ~/.ssh # This will force SSH and SCP to re-generate keys to the remote host.
tools.kiranbot4@tools-sgebastion-10:~$ scp user@remote_host:/data/project/kiranbot4/scripts/test.txt ~/KiranBOT/scripts/ # Get prompted for a password on the remote machine

Frankly, richardtoohey2 pointed you in the right direction in post #4...

Don't just blindly copy-paste the commands, try to understand them. Even one string like user@remote_host...txt has many parts to it, and they are all there for a reason - to accomplish the copying task for you.
 
Issue has nothing to do with ssh(1), it's a permission issue, plain and simple. Take a really long, hard look at the 600 permissions of /home/usernamekiran/ and try to understand what this means.
 
gpw928 richardtoohey2 astyle SirDice Thank you everybody. Actually, there were two different problems. It had been a very long time since I had used the actual SSH from terminal (I was using putty, and winscp on Windows for almost 5 years, company/employer policy).

I was having a feeling that something was off with the command. The command was supposed to be entered on the local machine's terminal, and not on SSH terminal. So the correct syntax would be:
usernamekiran@localmachine:~ % scp usernamekiran@login.<remote host>:/data/project/kiranbot4/test.txt /path/to/local/destination

The second problem was related to switching users like I mentioned in my post #5:
my key is configured for the user `usernamekiran`. After logging in, I have to switch by using "become kiranbot4"
The problem was, the file permissions were set differently for "kiranbot4", and "usernamekiran". But I diagnosed, and solved this issue as soon as it occurred.
While I was on remote/SSH terminal, the command by default was trying to paste the file at the remote destination as richardtoohey2 correctly deduced.

Thanks again everybody. I will try to be more active in the forums, and try to help others if I can.
Regards,
usernamekiran.
 
BTW, permissions wouldn't even matter if you use proper syntax for scp. If you're tools.kiranbot4 on localhost, but usernamekiran on remote, your scp command would look like this:
Code:
tools.kiranbot4@tools-sgebastion-10:~$ scp usernamekiran@remote_host:/data/project/kiranbot4/scripts/test.txt ~/KiranBOT/scripts/

You will get prompted for the password that usernamekiran uses on remote host, and then permissions wouldn't be an issue at all.
 
Back
Top