Posts Tagged ‘ssh’

Accessing Free Guangzhou Airport Wi-Fi on MacBook Pro

Saturday, December 2nd, 2017

Guangzhou airport has a crazy way of providing free wifi. If you have a Chinese phone you can receive a login account via text, but if you don’t have a Chinese number, then you have to go to a physical ticket machine, scan your passport, and quickly jot down (or photograph) the code that flashes on the screen for 15 seconds.

Once you have this code, you have to click “Ticket Cert” on the login page and enter the info.

This worked fine for me on my iPhone.

But when I tried to follow the same steps on my laptop, the “Ticket Cert” option did not appear on my browser login prompt. I saw a slightly different page that only had the SMS option (and a bunch of half-loaded CSS and javascript errors).

I tried many things including spoofing the UserAgent on my browser. Nothing seemed to work.

Finally, I changed the MAC address on my laptop to match my already-online iphone’s

ifconfig en0 ether [iphone's "Wi-Fi Address"]

This worked.

PS: So far, I have not managed to get any sort of vpn, proxy or ssh tunnelling to work.

Download web file onto a server from client

Tuesday, March 19th, 2013

If I want to download a file from a URL I can use wget. Then I can use scp to copy to my webserver. Or I could ssh to the server and call wget from there. Here’s a one-liner to do just that:


ssh SERVER 'wget URL -O LOCAL_SERVER_OUTPUT_FILE'

Making mercurial feel like svn

Sunday, November 11th, 2012

Stop asking for my password all the time

The easy way to fix this is to add your password in plain text to your .hgrc file.

The better way is to use SSH. We were currently using RhodeCode to serve up our mercurial repos but its easy to use SSH instead.

For exiting projects just change the [project]/.hg/hgrc file from:


[paths]
default = https://[hg username]@[server]/hg/[project]

to


[paths]
default = ssh://[ssh username]@[server]/hg/[project]

Notice that your [hg username] might be different from your [ssh username].

Update: I’m still figuring this one out…

One-liner commit,push and pull,update

To automatically push after every commit just add the following to your ~/.hgrc:


[hooks]
pre-commit = echo "\x1B[00;32mAutomatically pushing\x1B[00m"
commit.autopush = hg push

The echo serves as a reminder that each commit is really pushing.

To automatically update after each pull, just issue:


hg pull -u

One liner to add public key to authorized ssh keys

Monday, November 5th, 2012
cat ~/.ssh/id_rsa.pub | ssh jacobson@pascal.cs.columbia.edu 'mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys'

Perl warnings logging into blue host server from Switzerland

Wednesday, October 17th, 2012

I got the following warnings logging into my Bluehost web server from Zurich:


perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_CTYPE = "UTF-8",
	LANG = "en_US.utf-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_CTYPE = "UTF-8",
	LANG = "en_US.utf-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_CTYPE = "UTF-8",
	LANG = "en_US.utf-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

To disable them I just commented out the following line to look like:


SendEnv LANG LC_*

in the /private/etc/ssh_config file on my client-side mac.
source

scp hangs only in one direction

Wednesday, September 14th, 2011

I was recently having a very weird problem. I could not scp files from my local machine to my account on a web server (push files from my local machine to the server). Scp would just hang trying to execute. I could however ssh onto that account on the web server. And from there I could scp files from my local machine to the server (pull files from my local machine onto the server). I switched on the verbose flag and saw this:


scp -v some-local-file.txt username@web-server
Executing: program /usr/bin/ssh host web-server, user
username, command scp -v -t .
OpenSSH_5.2p1, OpenSSL 0.9.8l 5 Nov 2009
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to web-login.inf.ethz.ch [129.132.216.54] port 22.
debug1: Connection established.
debug1: identity file /Users/ajx/.ssh/identity type -1
debug1: identity file /Users/ajx/.ssh/id_rsa type 1
debug1: identity file /Users/ajx/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'web-login.inf.ethz.ch' is known and matches the RSA host key.
debug1: Found key in /Users/ajx/.ssh/known_hosts:30
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
web-login - iiRHEL 5Server (5.7.0.3) [WEB_SERVER]
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/ajx/.ssh/identity
debug1: Offering public key: /Users/ajx/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending command: scp -v -t .

And thats where it would hang forever.

After a long back and forth with the IT department we finally found my stupid mistake. When I first starting using this account on the web-server I was annoyed that the default shell was tcsh so I made a litte .tcsh/.tcshrc file which contained simply:


exec bash

This was the culprit. I don’t exactly understand why but removing this file made everything work. (In the end, I changed my shell to bash using the official method via the systems administration of the server).

Log into server with ssh, update svn one-liner

Thursday, September 1st, 2011

We use svn to manage the IGL website. This has its ups and downs. Unfortunately the permissions on the ETH servers are set up so that only a single account can be used to update the server version. Thus every time we make local edits we need to log into the server as this account and issue svn update. Luckily ssh lets you roll a single command into the ssh command. Thus this whole procedure can be condensed into a one-liner:

ssh username@server.com "svn update path/to/version/controlled/dir/"

I save this in my bash .profile with an alias:


alias svnupdateusername="ssh username@server.com \"svn update path/to/version/controlled/dir/\""

Then I can just locally issue:


svnupdateusername

The only problem I have with this is that when svn prompts me for the username’s password it no longer hides my input, which is annoying because in the version of universe in which I care about security I have to clear my terminal and look over my shoulder.

Turn off rm, mv interactive prompting when ssh-ed into access.cims.nyu.edu

Wednesday, December 16th, 2009

When I ssh into access.cims.nyu.edu and issue a rm or mv command I am bombarded with prompts for every file. For example if I issue:

rm *.pdf

I have to type yes <ENTER> for every pdf in the current directory.

I have tried the -f option listed in the rm man page, but I’m still prompted. I wondered if there was a way to turn this prompting feature off. It would
be very convenient if rm-ing and mv-ing acted the same way in access.cims.nyu.edu as the other unix and linux machines I used, use and will use.

I emailed the Courant help desk and got a solution:

That’s because in the system-wide .bashrc, the mv, cp, and rm commands are aliased to “mv -i”, “cp -i”, and “rm -i”. To unalias these commands in your environment, you just need to add the following lines to the end of your ~/.bashrc.


unalias rm
unalias mv

I did just that and now everything works fine.

Test ssh connection speed

Thursday, November 19th, 2009

Having a few different ssh hosts these days it’s become convenient to be able to test my upload and download transfer rates. Here’s my SSH speed test bash script. It uses dd to generate a test file then uses scp to test the transfer rates across the network.

#!/bin/bash
# scp-speed-test.sh
# Author: Alec Jacobson alecjacobsonATgmailDOTcom
#
# Test ssh connection speed by uploading and then downloading a 10000kB test
# file (optionally user-specified size)
#
# Usage:
#   ./scp-speed-test.sh user@hostname [test file size in kBs]
#

ssh_server=$1
test_file=".scp-test-file"

# Optional: user specified test file size in kBs
if test -z "$2"
then
  # default size is 10kB ~ 10mB
  test_size="10000"
else
  test_size=$2
fi


# generate a 10000kB file of all zeros
echo "Generating $test_size kB test file..."
`dd if=/dev/zero of=$test_file bs=$(echo "$test_size*1024" | bc) \
  count=1 &> /dev/null`

# upload test
echo "Testing upload to $ssh_server..."
up_speed=`scp -v $test_file $ssh_server:$test_file 2>&1 | \
  grep "Bytes per second" | \
  sed "s/^[^0-9]*\([0-9.]*\)[^0-9]*\([0-9.]*\).*$/\1/g"`
up_speed=`echo "($up_speed*0.0009765625*100.0+0.5)/1*0.01" | bc`

# download test
echo "Testing download from $ssh_server..."
down_speed=`scp -v $ssh_server:$test_file $test_file 2>&1 | \
  grep "Bytes per second" | \
  sed "s/^[^0-9]*\([0-9.]*\)[^0-9]*\([0-9.]*\).*$/\2/g"`
down_speed=`echo "($down_speed*0.0009765625*100.0+0.5)/1*0.01" | bc`

# clean up
echo "Removing test file on $ssh_server..."
`ssh $ssh_server "rm $test_file"`
echo "Removing test file locally..."
`rm $test_file`

# print result
echo ""
echo "Upload speed:   $up_speed kB/s"
echo "Download speed: $down_speed kB/s"

Note: I’m still looking for a good way to test general internet upload and download speed via the command line… Save it in a file called scp-speed-test.sh. Then run it with the command:

bash scp-speed-test.sh user@hostname

Back up user directory using rsync over ssh as hourly cron job

Wednesday, November 18th, 2009

First I followed this blogger’s instructions to set up my ssh password so that my script wouldn’t have to prompt for a password. I tested this by sshing into my destination server (shouldn’t ask for password now). There I made a directory to put my backup:


mkdir ~/macbook-pro-backup

I don’t want to back up everything in my user directory so I made an exclude file at ~/.cims-exclude-list:


/ajx/Library
/ajx/Music
/ajx/Movies
/ajx/Pictures
/ajx/Documents/Parallels
/ajx/Downloads
/ajx/Desktop
/ajx/.Trash
*.mp3
.DS_Store

Then I constructed and tested my rsync command:


rsync -e ssh -avz --exclude-from ~/.cims-exclude-list ~ jacobson@access.cims.nyu.edu:macbook-pro-backup

Note: I have not used the --delete option because for now I have the space available on my destination server, but eventually I will probably have to start deleting older, no-longer-existent files.

After I used the above command to do the initial (big/long) transfer, knowing that it works I constructed this bash script to keep a nice log. I saved this in cims-backup.sh:


#!/bin/bash
touch ~/.cims-backup.log
if rsync -e ssh -az --exclude-from ~/.cims-exclude-list ~ \
  jacobson@access.cims.nyu.edu:macbook-pro-backup
then
  echo "Back up succeeded on $(date)" >> ~/.cims-backup.log
else
  echo "Back up failed on $(date)" >> ~/.cims-backup.log
fi

Issue the following command to make this file executable


chmod -x cims-backup.sh

I ran this (bash cims-backup.sh) a couple times and checked the log file: cat ~/.cims-backup.log should produce something like


Back up succeeded on Wed Nov 18 16:23:49 EST 2009
Back up succeeded on Wed Nov 18 16:24:04 EST 2009

To be sure I sshed into my destination server and checked the macbook-pro-backup directory.

All that’s left is to set up an hourly cron job. To do this, in the terminal issue:


crontab -e

Then add this line and save:


0 * * * * /path/to/cims-backup.sh

If you are using vim to edit and you are getting this error:


crontab: temp file must be edited in place

then add this line to your .vimrc file:


set backupskip=/tmp/*,/private/tmp/*