mount to webdav over terminal command with user credentials - macos

I'm trying to mount to a webdav share over terminal on OS X. But it doesn't work very well.
mount_webdav -i "http://<ip-address>:80/Path/" "/Path/To/mntpnt/"
This is working, because it's prompting for username and password.
BUT!
mount_webdav -i "mount_webdav "http://<windomain>;<username>:<Password>#<ip-address>:80/Path/" "/Path/To/mntpnt/"
This command above don't work.
Have someone a good idea?
Is it possible to automate the -i command over a bash script?

If you store your username and password into your OS X keychain, mount_webdav should automatically pick it up.
s a sidenote, I was under the impression that it's a bad idea to call mount_webdav directly, and you should go via mount instead. But it's possible that that's only true for linux.

Related

Automating SFTP password authentication on macOS for use with -b batch processing?

I want a script to upload daily files using sftp. Unfortunately, the remote server doesn't support ssh keys (it's my customer's server and for some reason they can't or won't change it despite countless recommendations). So I need to somehow log in automatically using password authentication.
I found many different solutions (here on SO and elsewhere) but they all seem to use tools like sshpass, spawn, expect, send etc. Unfortunately my script is to be used on macOS and these tools aren't available there.
I fully realize it is NOT secure to use plaintext passwords in a script or on the command line. But using ssh keys is simply not an option at this stage.
So, is it possible to run sftp from the shell and specify the password either on the command line in plaintext, or specify some argument with a filename that contains the password?
Addition: after #MartinPrikryl's comment I got sshpass to work, by using brew install esolitos/ipa/sshpass.
However now I found out this doesn't work properly when I use the -b batch.txt parameter for sftp to process a bunch of commands. The batches I'm processing are typically a bunch of get and put commands.
So this works:
sshpass -f MyPassword.txt sftp rocketnuts#example.com
(I am logged in and getting the sftp prompt)
But this does not:
sshpass -f MyPassword.txt sftp -b list.txt rocketnuts#example.com
I'm getting this error:
rocketnuts#example.com: Permission denied (password).
So apparently the way sshpass sends the password to sftp somehow interferes with the batch input from the -b parameter.
Is there a way to make sshpass (or another form of scriptable authentication) work in combination with the -b option??
First, you can install sshpass even on MacOS:
How to install sshpass on Mac?
Though indeed, with -b switch, the sftp probably cannot accept a password, as the -b disables all interactive input (what sshpass simulates).
As an alternative to -b, you can use an input redirection:
sshpass -f MyPassword.txt sftp rocketnuts#example.com < list.txt

Applescript to mount remote file system through sshfs with password authentification

I am using sshfs (with OSXFUSE) to mount a remote file system on a local directory. In the terminal it looks like
sshfs username#myremoteserver.com: /path/to/local/directory
Then it asks for my password and done.
How can I include this in an applescript?
I tried
do shell script "sshfs username#myremoteserver.com: /path/to/local/directory"
but it does not do anything, which I expect is because it is waiting for a password. I don't know how to prompt securely for a password, pass it to bash and run the ssh command. Ideally I would like to do this without opening a terminal window. Note that the password may change all the time so that I cannot use the Keychain Access.
This other question is similar but only works for the superuser password.

SSH doesn't ask for my password

I've been logging in to this server through the terminal in coda 2, which has a spot to enter my password in the gui. Unfortunately, it keeps disconnection while sass is watching a file and I have to restart it. I was hoping to just ssh through the OSX terminal and keep it open separate from Coda. I can ssh without a password because it uses a key, but it only logs in to my home folder and I can't access the root(and it says I'm not in sudoers file). Somehow the password is being sent through coda and allowing me adequate access, but I'm not sure how it is sending the password.
How do I force SSH to ask for my password even though it's set to use the key?
Just pass these options to OpenSSH:
ssh -o PreferredAuthentications=keyboard-interactive -o PubkeyAuthentication=no user#host

Getting sudo to ask for password via the GUI

I have a lua script, running on the Mac, that needs to call sudo.
I'd hoped that Mac OS would automatically bring up a password request dialog, but instead it the command fails by returning 256.
Is there anyway that I can achieve my goal?
Tim
Quick and easy way: run it like this
/usr/bin/osascript -e 'do shell script "/path/to/myscript args 2>&1 etc" with administrator privileges'
Proper and configurable way: use AuthorizationExecuteWithPrivileges API from Authorization Services (in Security.framework).
Both will display standard Mac OS X GUI asking for administrator password and then execute the command as root, the same way as sudo does except that SUDO_USER environment variables will not be set.
If you need to execute individual commands from under user account when you're already elevated to root, you can prepend them with /usr/bin/sudo -u $USER.

Mac Terminal Keeps Asking for Password When Using PPK with SSH

I am attempting to connect to an Amazon EC2 Server via Mac Terminal. I have a PPK file that does not have a password attached to it, but when I try to connect I get a popup box that says "Enter the password for the SSH Private Key."
So we tried creating a PPK that has a password - but it does not accept the password, it still rejects the connection.
I have a Windows user who is able to connect using the same PPK on Putty.
Has anyone experienced this issue?
The mac is looking for a .pem key. The ppk is generated specifically for putty. If you don't have the original ppk key.
Download puttygen.exe from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Then go to conversions -> export OpenSSH key. Save the output as a .pem file and try using that with the mac.
If this doesn't work can you post the command you're running from mac. Its possible you've got some extra parameter or something.
Maybe your problem is with permissions for your key. I know in linux its required to change the permissions.
Taken from the website http://om4.com.au/ssh-rsa-key-pairs-passphrases-leopard/
Clear the contents of your ~/.ssh directory and set the directory permissions to 700 (directories need to be "executable")
$ rm ~/.ssh/*
$ chmod 700 ~/.ssh
Generate your rsa key pair (there are variations for this, but this is the version I used):
$ ssh-keygen -t rsa
Set the permissions for all files in ~/.ssh to 600
$ chmod 600 ~/.ssh
Copy your id_rsa.pub key to your server’s .ssh/authorized_keys file
Add your passphrase to your keychain using this command:
$ ssh-add -K
(you will see Enter passphrase for [your system]/.ssh/id_rsa: )
The error Enter your password for the SSH key x can result from using a key of the wrong format (such as a ppk key) in ssh or sftp. This is because it is interpreted as an encrypted ssh key and so prompts for the passphrase, when actually there is no passphrase.
In OS X I was able to simulate this error by simply typing the following into the command line:
sftp -o IdentityFile=randomtextfile mysftpserver.com
The solution is to convert the file using puttygen as suggested by bwight.
In addition to the other answers, the issue might come from the fact you haven't specified which user you want to connect as.
For example ssh -i francky.pem 208.52.170.43 will ask you for your password on Mac, whereas ssh -i francky.pem root#208.52.170.43 shouldn't. Note that on Linux you don't specify the user.
I was running into the exact same problem in MAC, I found a quite simple way of getting rid of it.
Instead of using ssh -i IP address, use the following>
ssh user#IP
Hope you already found the answer after this long time :)
In my case, the problem was the file's break type. Try this:
1.- Open the .pem file with TextWrangler
2.- At Bottom of app, verify if the Break Type is "Windows(CRLF)".
This issue had me pulling my hair out for 20 min or so. Realized that I was able to connect successfully from another terminal window. In my case I just had to close out the current terminal window and use another or new window. Very strange, but may help you out.

Resources