How would I configure a proxy in OSX terminal [closed] - terminal

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 6 years ago.
Improve this question
How would I add and activate a proxy for my computer via terminal (without going into System Preferences.) Can I do that with scutil --proxy somehow? I'm running on OSX Yosemite with a MacBook Air

Method 1
We can use awk to parse the output of scutil and extract the proxy configuration. The following snippet does the trick:
$ export http_proxy=`scutil --proxy | awk '\
/HTTPEnable/ { enabled = $3; } \
/HTTPProxy/ { server = $3; } \
/HTTPPort/ { port = $3; } \
END { if (enabled == "1") { print "http://" server ":" port; } }'`
$ export HTTP_PROXY="${http_proxy}"
This script looks for HTTPEnable, HTTPProxy, and HTTPPort in the output of scutil. If the proxy is enabled, the script prints out the proxy URL and sets it as the http_proxy environment variable. If the proxy is not enabled, the script sets http_proxy to an empty string. The final line sets the HTTP_PROXY environment variable as well since some command-line applications use that instead.
Placing this snippet in your .bash_profile ensures that your proxy will stay configured automatically while switching between wired and wireless networks.
Method 2
You could try creating a bash login script that uses one of the following uses of "networksetup" to list the current proxy, and then parse out the server address and apply it to the current terminal session:
networksetup -getftpproxy <servicename>
networksetup -getwebproxy <servicename>
networksetup -getsecurewebproxy <servicename>
networksetup -getstreamingproxy <servicename>
networksetup -getgopherproxy <servicename>
networksetup -getsocksfirewallproxy <servicename>
There may be other uses of the networksetup tool that can give you the specific proxy you are using, just look up "man networksetup" to see all the details and uses.
Method 3
Terminal does not use proxy settings configured in the network preferences pane because it doesn't do any connection. Terminal just let you fire commands which will use the network in different ways.
export http_proxy="username:password#proxyserver:port"
reference: https://dmorgan.info/posts/mac-network-proxy-terminal/

I wrote a little tool that does exactly that. Usage is straightforward.
Compile it with xCode.
Add:
eval `./path/to/export-proxies`
to your .profile, .bashrc, or .bash_profile.
It will set all commonly used proxy environment variables ($HTTP_PROXY, $http_proxy, $HttpProxy, etc.) for all protocols (HTTP, FTP, SOCKS) including all exceptions as defined in the OS X control panel.
Suggestions and improvements are also always welcome ;)
EDIT
I just saw you want to set the settings instead of reading them. I haven't found a way to do this so far. But would be happy to learn otherwise...

Related

How to execute a scp command inside an ssh session? [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 4 years ago.
Improve this question
How to copy a file located locally in my folder, while being connected in SSH?
This command works perfectly, but only when I run it locally:
scp /home/josh/Desktop/DATA/import/file001.csv root#10.0.3.14:/var/www/html/project
I would like to have the same result in launching it by being connected in ssh, is it possible?
You can setup ControlMaster in your .ssh/config
ControlMaster auto
ControlPath ~/.ssh/control:%h:%p:%r
Then use ssh command mode which will reuse existing connection:
Solution with push ssh session into background:
local$ ssh remote
remote$ ~^Z # Shift+`, Ctrl+z - Push ssh into background
local$ scp file remote:/remotepath
local$ fg
remote$
You can also to open tunnel via:
remote$ ~C # Shift+`, Shift+c - Enter command mode
ssh> -R15000:localhost:22 # tunnel to local:22 from remote:15000
Forwarding port.
remote$ scp -P15000 localhost:/filepath ~/
remote$ ~C
ssh> -KR15000
Canceled forwarding.
remote$
STEP 1 : Get the ip address
hostname -I
STEP 2 : Call SCP into SSH
scp josh#my_ip_address:~/Desktop/DATA/import/file001.csv /var/www/html/project
ie: "josh" is my name for the connection into my PC

SCP username with colon [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 5 years ago.
Improve this question
In order to log into a dedicated server via SSH, i use the following command:
ssh -p 49276 myusername:1001#server.address.net.com
The :1001 after the username is required for me to log in.
I'm now trying to scp some files from this server, using the following command:
scp -P 49276 myusername:1001#server.address.net.com:/var/www /localfolder
But when I do that, I get an error:
Could not resolve hostname myusername: nodename nor servname provided, or not known
I assume it's because of that colon after my username. How would I SCP using these credentials?
This is simply a feature of the Cisso ssh server implementation; it
parses the user name, and if it contains a :[0-9]+ component then it
understands it has to connect the session to the console port with the
corresponding number.
From here https://unix.stackexchange.com/questions/187658/integer-after-username-in-openssh-client-separated-by-colon
Try this:
scp -P 49276 -o User=myusername:1001 server.address.net.com:/var/www /localfolder
This might be a convoluted method, but I believe it will work for your case.
You can define hosts in your ~/.ssh/config file. There you can specify a username to use for a specific hostname. For example -
Host myhostname
User myusername:1001
HostName myhostname.com
Port 49276
With this in your ~/.ssh/config file, you'll be able to use an scp command similar to this -
scp myhostname:/var/www /localfolder
The host will be used together with the specified user and ports in the config file.
A pretty old link, but still useful info on ssh config files:
http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/

Getting wifi passwords with a mac

I'm trying to use the bash shell to get a wifi profile for a certain network, and from that, the password
What I'm looking for is basically a mac equivalent to netsh wlan show profile name="name" key=clear, which gets exactly what I want with windows
I have looked into the airport and networksetup commands on mac, but still have yet to find something that will either show me the network profiles or, even better, what's inside.
Does anyone have any ideas or at least something to point me in the right direction?
If it's okay to use a Node.js script for this, you might have a look at wifi-password-cli which does exactly what you want:
$ wifi-password --help
Usage
$ wifi-password [network-name]
Example
$ wifi-password
unicorns
$ wifi-password foo-network
foosecretpassword
(Sample taken from the tool's documenation)
To use it, simply run (supposed that Node.js has already been installed on your system before):
$ npm install -g wifi-password-cli
The simple way is:
security find-generic-password -ga "ROUTERNAME" | grep "password:"
Add the WIFI name you are connected in the place of ROUTERNAME
Simply run the command from terminal app
security find-generic-password -wa <WIFI_NAME>
Replace <WIFI_NAME> with your Wifi Name.
A prompt will ask you for username and password.

How to open putty using batch and login then execute list of commands on bash [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 6 years ago.
Improve this question
I have a Sun OS server with oracle configured on it ; with database 11g i want to take backup , now am connecting to terminal using ssh on putty console but , what i need is finding a way to make it possible to connect using batch to ssh to the server then login then login to oracle then take the backup, is that possible and how.
If you really want to use putty to do this you can use the below in your command prompt in Windows(this will open the putty and its terminal and execute the passed argument in you text file):
putty.exe plink -ssh -load profileName -l username -pw password -m commandPath -t
Or
putty.exe -ssh username#ip -pw password -m commandPath
e.g:
putty.exe -ssh rootz#10.10.10.10 -pw rootzpass -m c:\commands\mycommands.txt
Where profileName is the profile saved in putty and the commandPath is your local directory text file containing the commands you want to execute and the username is the server user and ip is the IP address for the server , the password is your server password then you can put whatever commands you want in your textFile.
Reference
the.earth putty documentation

How can I transfer a file after having already logged in to a server via 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 8 years ago.
Improve this question
This is a rather odd and embarrassing situation for all involved.
Suppose someone (cough cough not me cough cough) accidentally chmod 000d my home directory on a remote server.
I had been using ssh keys to login, since I figured I would forget the actual password on the remote host (which I have). However, now that my home directory has 000 perms, the ssh key in ~/.ssh/authorized_keys is unreadable, and ssh forces me to put in a password that I have long since forgotten.
Also, I don't have sudo superpowers on the remote server.
HOWEVER, I happen to have an ssh session open to the remote server that started before someone (cough) chmod 000d my home directory.
All of this happened while I was trying to upload some files from my local host to a publicly accessible directory in my home directory.
CAN I STILL UPLOAD FILES FROM MY LOCAL MACHINE TO THE REMOTE MACHINE WITHOUT NEEDING A NEW SSH SESSION?!
I figure I could at least put them in /tmp or something for now.
Yes you can!
Press enter,~,Shift+C to open a ssh command line.
Enter -L 12345:localhost:12345 to forward a new port over your existing SSH connection
Run nc -l -p 12345 | tar xzv on your remote ssh session
Run tar czv FileOrDir1 FileOrDir2 Etc | nc localhost 12345 on your local system.
The files will now transfer over your existing ssh connection, and will appear in the current dir of your remote session.
Why you would want to do this instead of just chmod 711 ~ is beyond me though.

Resources