Using putty to scp from windows to Linux - linux

I'm trying to test some C code that I'm writing. The only issue is that the code needs to be executed on a remote machine.
My laptop is pretty old, and there is no driver for my wireless card available for Ubuntu, so booting into Linux to circumvent this problem isn't an option.
Here's my question:
I'm using putty to SSH into the remote machine, and I'm writing my code on Notepad++.
The location of my file is:
C:\Users\Admin\Desktop\WMU\5260\A2.c
My problem is that when I use the command scp C:\Users\Admin\Desktop\WMU\5260\A2.c ~
I get the error could not resolve hostname C:. Name or service not known".
I've also tried scp Users\Admin\Desktop\WMU\5260\A2.c ~ which gives me the error Cannot stat 'Users\Admin\Desktop\WMU\5260\A2.c': no such file or directory
What am I doing incorrectly?

You need to tell scp where to send the file. In your command that is not working:
scp C:\Users\Admin\Desktop\WMU\5260\A2.c ~
You have not mentioned a remote server. scp uses : to delimit the host and path, so it thinks you have asked it to download a file at the path \Users\Admin\Desktop\WMU\5260\A2.c from the host C to your local home directory.
The correct upload command, based on your comments, should be something like:
C:\> pscp C:\Users\Admin\Desktop\WMU\5260\A2.c ckg8221#thor.cs.wmich.edu:
If you are running the command from your home directory, you can use a relative path:
C:\Users\Admin> pscp Desktop\WMU\5260\A2.c ckg8221#thor.cs.wmich.edu:
You can also mention the directory where you want to this folder to be downloaded to at the remote server. i.e by just adding a path to the folder as below:
C:/> pscp C:\Users\Admin\Desktop\WMU\5260\A2.c ckg8221#thor.cs.wmich.edu:/home/path_to_the_folder/

You can use PSCP to copy files from Windows to Linux.
Download PSCP from putty.org
Open cmd in the directory with pscp.exe file
Type command pscp source_file user#host:destination_file
Ex.
pscp sample.txt myuser#myhost.com:/mydata/sample.txt
Reference

Use scp priv_key.pem source user#host:target if you need to connect using a private key.
or if using pscp then use pscp -i priv_key.ppk source user#host:target

Related

Can not copy files From Azure VM to local Windows

I want to copy file from Azure Linux VM to local Windows PC. Actually I remember, I could do this perfectly with the same command but now when I run the cmd it shows message as 100% done but when I go to tmp directory, I dont see the file there.
Here is the cmd I give on Linux VM:
scp -r mlopenedx#138.91.116.170:/edx/var/log/tracking/tracking.log /tmp/
And this is output I get:
tracking.log 100% 70KB 70.0KB/s 00:00
But when I see tmp folder I dont see the file.Can any on suggest me the answer.
I have tried things like: giving Home folder ~/ instead of /tmp/.
Also tried below cmd:
sudo scp -i ~/.ssh/id_rsa mlopenedx#MillionEdx:/edx/var/log/tracking/tracking.log /tmp/
The easiest way to do this is to run pscp from windows like this:
pscp mlopenedx#LINUXVMIP:/edx/var/log/tracking/tracking.log c:/someExistingFolder/tracking.log
to have pscp command you need to install PuTTY.
your command looks wrong as one of the paths needs to be Windows valid path C:/Folder/Folder/File.ext. If you are executing that command from Linux VM and 138.91.116.170 is your Linux vm IP address than you are copping files locally - you can try finding your log file on that linux in \tmp\ folder. In order for that to work from remote Linux to local Windows you would need public IP for your windows or some sort of tunnel that would allow this connection.
Also you are adding -r recursive copy and you are pointing to file.

pscp between linux and windows

I am trying to scp file(s) from window to linux.
user is windows system, we are executing pscp from linux command
Command used :
pscp user#ip:source dest
It shows :
unable to identify source: permission denied
If I use it in this way,
pscp source user#ip:dest
It works fine and copy the files to windows.
Am I using correct format?
We need to copy from remote windows, but the commands needs to be invoked from local linux system.
Here is an example of how I copy a file from my windows machine to my linux machine
C:\Users...\Downloads>pscp -i "DEV_IRM.ppk"
product-sp-4.2.0-rc2.tar.gz
prvclouduser#10.149.137.26:/home/prvclouduser/sp420
Make sure that you are in the directory where the file you want to copy is located. In my case 'Downloads' directory.
Private key for access: DEV_IRM.ppk
My linux server: prvclouduser#10.149.137.26
The landing directory in linux: /home/prvclouduser/sp420 (make sure this exists; do pwd to confirm full path)

How to run SUDO command in WinSCP to transfer files from Windows to linux [duplicate]

This question already has answers here:
WinSCP connect to Amazon AMI EC2 Instance changing user after login to "root"
(6 answers)
Closed last year.
I am trying to use WinSCP to transfer files over to a Linux Instance from Windows.
I'm using private key for my instance to login to Amazon instance using ec2-user. However ec2-user does not have access to write to the Linux instance
How do I sudo su - to access the root directory and write to the Linux box, using WinSCP or any other file transfer method?
Thanks
I know this is old, but it is actually very possible.
Go to your WinSCP profile (Session > Sites > Site Manager)
Click on Edit > Advanced... > Environment > SFTP
Insert sudo su -c /usr/lib/sftp-server in "SFTP Server" (note this path might be different in your system)
Save and connect
Source
AWS Ubuntu 18.04:
There is an option in WinSCP that does exactly what you are looking for:
AFAIK you can't do that.
What I did at my place of work, is transfer the files to your home (~) folder (or really any folder that you have full permissions in, i.e chmod 777 or variants) via WinSCP, and then SSH to to your linux machine and sudo from there to your destination folder.
Another solution would be to change permissions of the directories you are planning on uploading the files to, so your user (which is without sudo privileges) could write to those dirs.
I would also read about WinSCP Remote Commands for further detail.
Usually all users will have write access to /tmp.
Place the file to /tmp and then login to putty , then you can sudo and copy the file.
I just wanted to mention for SUSE Enterprise server V15.2 on an EC2 Instance the command to add to winSCP SFTP server commands is :
sudo su -c /usr/lib/ssh/sftp-server
I didn't have enough Reputation points to add a comment to the original answer but I had to fish this out so I wanted to add it.
ssh to FreePBX and run the commands stated below in your terminal:
sudo nano -f /etc/sudoers.d/my_config_file
YourUserName ALL=(ALL) NOPASSWD:ALL
sudo systemctl restart sshd
Winscp:
under session login ==> Advanced ==> SFTP
Change SFTP Server to:
sudo /usr/libexec/openssh/sftp-server
I do have the same issue, and I am not sure whether it is possible or not,
tried the above solutions are not worked for me.
for a workaround, I am going with moving the files to my HOME directory, editing and replacing the files with SSH.
Tagging this answer which helped me, might not answer the actual question
If you are using password instead of private key, please refer to this answer for tested working solution on Ubuntu 16.04.5 and 20.04.1
https://stackoverflow.com/a/65466397/2457076

Blank SSHFS mount folder

I am attempting to mount a remote directory located on my web server to a directory in my xUbuntu installedation hosted in a VirtualBox.
I'm using the following command syntax:
sshfs root#*.*.*.*:/var/www Desktop/RemoteMount
Using the file manager, I navigate to the Desktop/RemoteMount directory but find it entirely blank. The SSHFS command above executed with no indication of an error.
Completely by chance, I use the terminal to long list the contents of the Desktop/RemoteMount directory and it shows all the data I was expecting to see in the file manager.
Can anyone tell me why the file manager does not show my remotely mounted data and how I might fix it?
Thanks.
you are missing local mountpoint.
sshfs -o idmap=user mika#192.168.1.2:/home/mika/remotepoint /home/mika/localmountpoint.
And You need to have localmount folder exist.
thanks Mika

Configuring PATH globally for SSH remote commands

I have a problem with the PATH variable on Debian Linux when executing commands via SSH. This happens for example when I use GIT or Mercurial and I have them installed in /opt instead of /usr/local. But I can also reproduce this easily like this:
When I login to the server via SSH in a normal way and then do echo $PATH then I get the PATH which I have configured in /etc/profile:
/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/maven/bin:/opt/ant/bin:/opt/mercurial/bin:/opt/git/bin
But when I do ssh user#server 'echo $PATH' instead then I get this:
/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
The same happens when I use GIT or Mercurial with an ssh URL. It can't find hg or git executable on the server because it don't get the PATH from /etc/profile.
So the question is: Is there a "more global" way to configure the PATH so it also works with SSH remote execution? Configuring the PATH per user is not an option. Specifying the full path to git/hg executables when using git/hg on the client is also not an option. And I know that I could use symlinks or wrapper scripts in /usr/local/bin to get it working but I'm searching explicitly for a possibility to have a correct PATH when executing commands remotely via SSH.
On Debian, the standard environment is setup through pam_env (in /etc/pam.d/sshd), which will read /etc/environment and /etc/security/pam_env.conf. You can either edit those, or you add another pam_env line to the pam configuration, pointing to an environment file specific to SSH logins.
While not an answer to your problem, from this link, it looks like ssh has a path settings of its own.
The ssh server set some environment variables at the start of the session. You can create a ~/.ssh/environment file on the ssh server to set additional variables (assuming there is a BSD openssh server on the server), but the server must be configured to allow to change the environment.
If the above doesn't work, you can set the remote command. In mercurial this is the --remotecmd switch for push and pull.
I solved this issue by including all necessary files to the .bashrc
For instance:
. /etc/profile.d/rvm.sh
. /etc/profile.d/bash_completion.sh

Resources