Skip to content

Instantly share code, notes, and snippets.

@alexandrinos
Last active December 27, 2015 15:32
Show Gist options
  • Save alexandrinos/e755521413d0c6b6fc09 to your computer and use it in GitHub Desktop.
Save alexandrinos/e755521413d0c6b6fc09 to your computer and use it in GitHub Desktop.
Usefull commands network, environment Linux
#see https://help.ubuntu.com/community/SSH/OpenSSH/Keys
#add a public key to the authorized_keys on the server, if authorized_keys already exist on the server
cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
#add a public key to the authorized_keys on the server, if authorized_keys not exist
cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
#ssh-copy-id doesn't work here on Ubuntu with Myngw64 Win7
#use extended variant,for permissions issues
host=user@]machine;
ssh $host 'mkdir -pm 700 ~/.ssh; echo ' $key ' >> ~/.ssh/authorized_keys ; chmod 600 ~/.ssh/authorized_keys'
#copy a file using brackets short format
cp .bashrc{,.orig}
#create multiple files
touch /path/to/{file1,file2,file3}.txt
#list prefix
ls {a,b,c}.txt
#list sufix
ls *.{txt,doc}
#---Networking
#
#what process belongs to which port host User Protocol
#must run as sudo
sudo netstat -tulpne
#or short
sudo netstat -aupnt
#show internet sockets and local sockets splitted
sudo netstat -p
#---Processes
#
#what initiated the processes and what PID have
ps aux
#which ports are open and what process
nmap localhost
#---Aptitude(Ubuntu)
#
#short explanation of a software
aptitude search nfs
# DEBUG SSH
#on server side run; port any free port; d is the level of debug; one is the minimum debug
/usr/bin/sshd -ddd -p 2233
#you could use also another configuration file, for testing, like this
/usr/sbin/sshd -d -p 2233 -f /home/fred/sshd_config.test
#then on client run
ssh myuser@192.168.1.2 -vvv -p 2233
#on client you could run to show the config file
ssh user@machinde -G -p 2233
#or we can ssh with options only; anything is just an alias
ssh -o "User=apollo" -o "Port=4567" -o "HostName=example.com" anything
#other usefull commands on server to test the config file -> log user,host and address,
#with multiple parameters
/usr/bin/sshd -TC user=fred,host=server.example.org,addr=192.0.2.15
#also the localport and address
/usr/sbin/sshd -TC user=fred,host=server.example.org,addr=192.0.2.15,laddr=192.0.2.2,lport=2222
#shows environment of the current user; very usefull for debugging
# PATH, user home dir,tty number,mail path, term,shell path,ssh_client number and ports
env
#usefull for freezing window, fg jobs, command line binding(forwarding),forwarded connections
To use a sequence line:
press:
Enter
then press:
~ ?
Supported escape sequences:
~. - terminate connection (and any multiplexed sessions)
~B - send a BREAK to the remote system
~C - open a command line
~R - request rekey
~V/v - decrease/increase verbosity (LogLevel)
~^Z - suspend ssh
~# - list forwarded connections
~& - background ssh (when waiting for connections to terminate)
~? - this message
~~ - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline
#ssh to a remote and use the Gui programs that a remote uses on local machin !
ssh -X remote_host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment