automatic ssh session when moving to mapped sshfs [closed] - ssh

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
If you have a network drive mapped via sshfs, is there a way to automatically log on via ssh whenever changing to that directory?
$USER:$LOCALHOST:~: sshfs $USER:$REMOTEHOST /Volumes/dev0
$USER:$LOCALHOST:~: cd /Volumes/dev0
$USER:$REMOTEHOST:~

Thomas Jansson provides a guide on integrating sshfs with autofs. I'll summarize his guide here, so this answer will still be worth something if his site ever goes offline:
Create an /etc/auto.master:
/mnt/sshfs /etc/auto.sshfs uid=1000,gid=1000,--timeout=30,--ghost
Make sure your uid and gid match your userid and guid in /etc/passwd or whatever you use to provide system accounts.
Now add lines into /etc/auto.sshfs, one per desired filesystem, in the following form:
bar -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,max_read=65536 :sshfs\#tjansson#bar.com\:
Be sure to change tjansson#bar.com to whatever user account and hostname you're going to be using. Change the leading bar to whatever you'd like the directory to be named. When you cd /mnt/sshfs/bar, autofs will automatically mount the FUSE filesystem for you. Of course, using SSH keys and the ssh-agent(1) will make this far more pleasant.
Update
... create a directory that literally logs you into the other machine.
Hey, that's pretty clever idea. You could either write a shell function that checks the directory name you want to cd into and start a new ssh for you. Maybe you can (ab)use the PROMPT_COMMAND variable to ssh to the host if the directory name matches. Be warned that either approach will slow down your normal cd or every prompt display.
Another approach that I've used and enjoyed is a small little helper script, ~/bin/ssh-to:
#!/bin/bash
hostname=`basename $0`
ssh $hostname $*
Symlink new names to this shell script: ln -s ssh-to sarnold.org and then you can run a command or log in on a remote site without typing the ssh all the time:
sarnold.org python foo.py
It'll log you in to whatever machine you've used for the name of the symbolic link and run whatever command you give it.

Related

Raising the nofile limit under WSL2 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I'm not what you would call an advanced linux user, so my apologies for a probably dumb question.
I'm trying to raise the NOFILE limit for my UBUNTU 20.04 distro using WSL2, following this guide: cannot-increase-open-file-limit-past-4096-ubuntu
However, when I try to modify the corresponding .conf files I get a permision denied error.
When trying to do so from windows and VsCode I get:
Failed to save 'system.conf': Command failed: "C:\Users\sague\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd" --file-write "c:\Users\sague\AppData\Roaming\Code\code-elevated-mjlcag" "\\wsl$\Ubuntu-20.04\etc\systemd\system.conf" Error using --file-write: EPERM: operation not permitted, open '\\wsl$\Ubuntu-20.04\etc\systemd\system.conf'
And when trying to do so using nano within the WSL2 terminal (using windows terminal) I get:
Error writing /etc/systemd/system.conf: Permission denied
Please help, I'm stuck with this :')
My apologies for what is probably a very noob question
Well, to be honest you are making a few newbie mistakes, but don't worry - Even once you get past those, what you are trying to do under WSL isn't easy.
First, you are trying to edit a system file as a normal user in nano, resulting in Permission denied. Solution: Use sudo nano /etc/systemd/system.conf instead. But see below (3) for why this ultimately isn't going to work.
Second, you are trying to edit a WSL system file as a normal user under VSCode. This just won't work since VSCode always runs as the normal user by design. It may be possible to get it to run under sudo, but it's probably not worth the effort. Note that this is also a limitation when running the "Remote - SSH" extension in VSCode (similar to the "Remote - WSL" one you are using now).
You are trying to modify the systemd configuration under WSL, where there is no systemd support, so even when you do successfully edit the file, it isn't going to do anything.
Your next attempt once you got past that would probably be (as it is for most of us) to try to raise the ulimit through /etc/security/limits.conf, which is the right way to do it, but requires a trick under WSL. That file is a PAM construct, and ... well, PAM runs at login, and we don't "login" in WSL, so PAM usually doesn't get called.
The hacky solution, as I cover in this answer on Ask Ubuntu (with great assistance from a number of answers in this Github thread) is to make the modifications to /etc/security/limits.conf and then to force PAM to process it by sudo'ing back in as your own user via:
sudo su $USER
or possibly
sudo su - $USER # if you need to run as a login shell
There are also some other suggestions in the Github thread, if those incantations don't quite work for you.

Copying files from server to local computer using SSH [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I am having trouble copying files from a remote server using SSH. Using PuTTY I log in to the server using SSH. Once I find the file I would like to copy over to my computer, I use the command:
scp username#host.com:/dir/of/file.txt \local\dir\
It looks like it was successful, but it only ends up creating a new folder labeled 'localdir' in the remote directory /dir/of/.
How can I copy the file to my local computer over SSH?
It depends on what your local OS is.
If your local OS is Unix-like, then try:
scp username#remoteHost:/remote/dir/file.txt /local/dir/
If your local OS is Windows ,then you should use pscp.exe utility.
For example, below command will download file.txt from remote to D: disk of local machine.
pscp.exe username#remoteHost:/remote/dir/file.txt d:\
It seems your Local OS is Unix, so try the former one.
For those who don't know what pscp.exe is and don't know where it is, you can always go to putty official website to download it. And then open a CMD prompt, go to the pscp.exe directory where you put it. Then execute the command as provided above
EDIT
if you are using Windows OS above Windows 10, then you can use scp directly from its terminal, just like how Unix-like OS does.
Thanks to #gijswijs #jaunt #icanfathom
Your question is a bit confusing, but I am assuming - you are first doing 'ssh' to find out which files or rather specifically directories are there and then again on your local computer, you are trying to scp 'all' files in that directory to local path. you should simply do scp -r.
So here in your case it'd be something like
local> scp -r username#host.com:/path/to/dir local/path
If youare using some other executable that provides 'scp like functionality', refer to it's manual for recursively copying files.
You need to name the file in both directory paths.
scp username#host.com:/dir/of/file.txt \local\dir\file.txt
Make sure the scp command is available on both sides - both on the
client and on the server.
BOTH Server and Client, otherwise you will encounter this kind of (weird)error message on your client: scp: command not found or something similar even though though you have it all configured locally.
that scp command must be issued on the local command-line, for putty the command is pscp.
C:\something> pscp username#host.com:/dir/of/file.txt \local\dir\

What is the difference between bin/sh, bin/bash, sbin/nologin, bin/tcsh, etc? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I am new to linux so please go easy and talk slow =)
In Plesk I have some options for accessing the server over SSH. I just want to connect, add my public key and run rsync for backup.
What is the difference between these options?
Which option should I choose?
What are these? They look like directories to me.
Access to the server over SSH:
/bin/sh
/bin/bash
/sbin/nologin
/bin/tcsh
/bin/csh
/bin/ksh
/bin/bash (chrooted)
/bin/rbash
Here is an image of the Plesk control panel:
Use /bin/bash
What are these? They look like directories to me.
These are different options for default shell given to users who connect via SSH
If you haven't used any of these shells before, I think bash is the best option for you. Most tutorials and articles for linux commands online assume you are using bash.
However, you have two options for bash: /bin/bash and /bin/bash (chrooted).
To do backups, you will probably need the bash to have full access to execute all commands.
I'm not sure whether you can get what you want done with a chrooted bash.
Basically, chrooted bash is for avoiding mishaps.
To know more about chrooting, you can read this article
Most of options are various Unix shells. A shell is basically what interprets the text that you type in the window. Some people prefer one shell over others. If you are not familiar with any shell in particular, pick one based on your needs Comparison Chart
If you don't know, you should use /bin/bash. It's the most popular, and will be the easiest for you to get help using. That said, they all do the same thing, just in slightly different ways.

Change default file permissions on debian [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I've setup a Debian cloud server. I installed apache, php and then vsftpd. I created users and set permission etc.
When I upload a file, its default permissions are 600 and I can't view the file unless I manually change it to 774 or 775.
So, I'd like to change the default permissions of all files that I upload to /var/www/ to 754.
I know that chmod -R 754 /var/www makes all files within that directory to 774 but it doesn't change the default permissions of all new files that are uploaded.
My user is 'joe' for demo purpose since I'm learning, so I even tried chown -R joe /var/www but that didn't change the default permissions either.
How do I change it default permissions from 600 to 774? In which file should I write and what?
You should use umask. More info here: http://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html
You must change the umask of the user(s) writing to the directory. And BTW do NOT set execute permissions when they are not needed.
A umask is a negative mask of permissions which should be applied. By default, all files would be created with 666 and all directories with 777. With a umask of 002, which seems to be what you want, these become 664 and 775.
Now, how to set the umask depends on the program which actually writes the file, and whether this setting is available in its configuration file.
Another, less known way, would be to set POSIX ACLs to the upload directory: for this, you can use setfacl with the -d option on /var/www (provided your OS, and filesystem, support it both).
One of your comments suggests you are uploading the files through proftpd. If this is the case, then your question is really specific to that piece of software. The answer is not to go modifying /etc/profile, as that is going to change the default umask for all users that use Bourne Shell or similar (i.e. Bash). Furthermore, a user must actually log into the shell for /etc/profile to be read, and on a properly configured system, the user your daemon is running as does not actually log in. Check http://www.proftpd.org/docs/howto/Umask.html for information specific to proftpd and umasks.

ssh with passphrase [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
ssh user#host works (in a script via Apple Terminal)
does anybody know an easier way than ssh-agent to combine the passphrase with the ssh command ?
regards
You can use:
sshpass -p password ssh user#host
However if you wanted the luxory of not typing in your password, I would HIGHLY suggest setting up public/private ssh keys:
http://www.ece.uci.edu/~chou/ssh-key.html
and http://www.linuxproblem.org/art_9.html
This is extremely secure, and very convient.
For scrub just take a look to the configuration files of your installation of open ssh, cause you'll find every single option you can include or deactivete while you connect to the server. There is an option of fusemount for example if you'd like to have your machine conneted to the one in which you're logging in ( i used it with my netbook when they were REAL netbook and not computers). Fusemount is an option when you want more abilities to be added to you computer or you need data from both sides (the one of the server and the one of the client) but security cannot be omitted in any case.