SSH connection
Check for existing SSH keys
ls ~/.ssh
If you allready have key pair
ssh-keygen -R 192.168.2.70
Generate new SSH keys
To generate new SSH keys enter the following command (Choose a sensible hostname such as
ssh-keygen -t rsa -C eben@pi
You can also use a more descriptive comment using quotes if you have spaces, e.g. ssh-keygen -t rsa -C “Raspberry Pi #123”
Upon entering this command, you’ll be asked where to save the key. We suggest you save it in the default location (/home/pi/.ssh/id_rsa) by just hitting Enter.
You’ll also be asked to enter a passphrase. This is extra security which will make the key unusable without your passphrase, so if someone else copied your key, they could not impersonate you to gain access. If you choose to use a passphrase, type it here and press Enter, then type it again when prompted. Leave the field empty for no passphrase.
Now you should see the files id_rsa and id_rsa.pub in your .ssh directory in your home folder:
ls ~/.ssh
authorized_keys id_rsa id_rsa.pub known_hosts
The id_rsa file is your private key. Keep this on your computer.
The id_rsa.pub file is your public key. This is what you put on machines you want to connect to. When the machine you try to connect to matches up your public and private key, it will allow you to connect.
Take a look at your public key to see what it looks like:
cat ~/.ssh/id_rsa.pub
It should be in the form:
ssh-rsa <REALLY LONG STRING OF RANDOM CHARACTERS> eben@pi
Copy your public key to your device
If your Pi does not have an .ssh directory you will need to set one up so that you can copy the key from your computer.
cd ~
install -d -m 700 ~/.ssh
To copy your public key to your Raspberry Pi, use the following command to append the public key to your authorized_keys file on the Pi, sending it over SSH:
cat ~/.ssh/id_rsa.pub | ssh <USERNAME>@<IP-ADDRESS> 'cat >> .ssh/authorized_keys'
cat ~/.ssh/id_rsa.pub | ssh pi@192.168.2.71 'cat >> .ssh/authorized_keys'
cat ~/.ssh/id_rsa.pub | ssh pi@82.181.94.193 'cat >> .ssh/authorized_keys'
Make bash script runable
Give execute permission to your script:
chmod +x /path/to/yourscript.sh
And to run your script:
/path/to/yourscript.sh
Since . refers to the current directory: if yourscript.sh is in the current directory, you can simplify this to:
./yourscript.sh
Screen
Mount view
Type the df command shows more human readable output:
df -aTh
OR then
mount
mount -l
Unmount
umount /media/pi/usb
Disc space
df -h
ls -l --block-size=M
Wifi and Network
- Guide for setting wifi
sudo iwlist wlan0 scan | grep ESSID
Find LAN devices (works with OSX Terminal)
system("arp -a")
Filesystem
Give permission to testuser:testuser to dir
sudo chown -R testuser:testuser /var/www/test/public_html
rsync
system("rsync -arv --delete ~/folder/ ~/temp/")
Remove directory
and all it content
rm -rf directoryname
Copy files system to ssh
sudo cp filelocation pi@verkkovadelma:/home/pi
Connecting smb-services
View client shares
smbclient -L 192.168.2.90
Connect to share
smbclient \\\\192.168.2.90\\public
FTP services
curlftpfs -o allow_other ftp-user:ftp-pass@my-ftp-location.local /mnt/my_ftp/
User account and groups
Grant normal user to have permission to use GPIO.
sudo adduser my_new_user gpio
Add user to group
usermod -a -G GROUP USER
Remove User from Group
sudo gpasswd -d USER GROUP
Locales problemos
Solution
You can fix the issue by setting the locale to en_US.UTF-8 for example:
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales
Once you run the last command a dialog will appear to let you choose the desired locale.
Power options
Reboot
sudo reboot
Poweroff
sudo poweroff
Root
Top10 commands
ps aux | grep apache2
How to check Kernel version?
uname -a
uname -v
How to check ip address?
ifconfig
ip addr show
ip addr show wlan0
How to check disk space used?
df -ah
How to check process status?
service udev status
systemctl status udev
How to check folder size?
du -sh brootbot/
How to check what ports are being used?
netstat
netstat -tulpn
How to check CPU usage of certain process?
ps aux | grep apache2
htop
top
How to mount drive?
ls /mnt
mount /dev/sd2 /mnt/ab
How to check existing mounts?
mount
Mount file in boot, what file you would looking?
less /etc/fstab
How to find answer for commands?
man <command>
man ps